package com.qianhui.bean;

import com.qianhui.common.CM;
import com.qianhui.common.GlobalConfig;
import com.qianhui.common.IStatus;
import com.qianhui.dao.*;
import com.qianhui.pojo.*;
import com.qianhui.view.GoodsTypeView;
import com.qianhui.view.GoodsTypeViewAndList;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.*;

public class BatchTaskJob_OneDay implements Job
{

    private GoodsDAO goodsDAO = new GoodsDAO();
    private OrderDAO orderDAO = new OrderDAO();
    private OrderGoodsDAO orderGoodsDAO = new OrderGoodsDAO();
    private CommentDAO commentDAO = new CommentDAO();
    private BuyerDAO buyerDAO = new BuyerDAO();
    CommissionDayRecordDAO commissionDayRecordDAO = new CommissionDayRecordDAO();
    GoodsCommissionDAO goodsCommissionDAO = new GoodsCommissionDAO();
    OrderReturnDAO orderReturnDAO = new OrderReturnDAO();
    GoodsTypeDAO goodsTypeDAO = new GoodsTypeDAO();
    GoodsHistoryDAO goodsHistoryDAO = new GoodsHistoryDAO();
    CommissionDetailRecordDAO commissionDetailRecordDAO = new CommissionDetailRecordDAO();
    PreCommissionDayRecordDAO preCommissionDayRecordDAO = new PreCommissionDayRecordDAO();
    SimpleDateFormat sdf_month = new SimpleDateFormat("yyyy-MM");
    int onePageSize_2 = 2;
    int onePageSize_5 = 5;
    int onePageSize_10 = 10;

    @Override
    public void execute(JobExecutionContext arg0) throws JobExecutionException
    {
        System.out.println(CM.getTimeStrNow() + "每日凌晨3点的批量任务执行--开始");
        batch_count_goods_sales_comments();
        batch_delete_temp_qrcode();
        batch_export_goods_excel_file();
        batch_export_buyer_excel_file();
        batch_count_commission_day_record();
        batch_count_pre_commission_day_record();
        batch_export_buyer_report_file();
        batch_export_order_return_report_file();
        batch_export_order_report_file();
        batch_export_commission_detail_report_file();
        batch_export_goods_sales_summary_report_file();
        batch_export_commission_summary_report_file();
        System.out.println(CM.getTimeStrNow() + "每日凌晨3点的批量任务执行--结束");
    }

    private void batch_count_goods_sales_comments()
    {
        System.out.println("批量计算全网销售中商品的销量和评价数--开始");
        // 批量计算全网销售中商品的销量和评价数
        int allGoodsCountInDB = goodsDAO.getGoodsTotalCountByStatusAnd_tidAnd_keyword(IStatus.GOODS_IS_ON_SALE, null, null);
        int onePageSize = 100;
        if (allGoodsCountInDB > 0)
        {
            int ttpTemp = allGoodsCountInDB % onePageSize == 0 ? allGoodsCountInDB / onePageSize : allGoodsCountInDB / onePageSize + 1;
            for (int i = 1; i <= ttpTemp; i++)
            {
                List<Goods> goodsList = goodsDAO.getListByIndexAndPageSizeAndStatus(i, onePageSize, IStatus.GOODS_IS_ON_SALE);
                if (goodsList != null && goodsList.size() > 0)
                {
                    for (Goods g : goodsList)
                    {
                        int goodsTotalCount = orderGoodsDAO.getGoodsTotalCountByGoodsId(g.getGoodsId());
                        if (goodsTotalCount >= 0)
                        {
                            g.setGoodsSalesNumber(goodsTotalCount);
                        }

                        int goodsCommentNumber = commentDAO.getTotalCountByGoodsId(g.getGoodsId());
                        if (goodsCommentNumber >= 0)
                        {
                            g.setGoodsCommentNumber(goodsCommentNumber);
                        }
                    }
                    goodsDAO.saveList(goodsList);
                }
            }
        }
        System.out.println("批量计算全网销售中商品的销量和评价数--结束");
    }

    private void batch_delete_temp_qrcode()
    {
        System.out.println("批量删除过期的临时二维码图片，利用临时二维码保存的带有时间标记的文件夹来删除--开始");
        // 批量删除过期的临时二维码图片，利用临时二维码保存的带有时间标记的文件夹来删除
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DAY_OF_MONTH, -10);
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy");
        SimpleDateFormat sdf2 = new SimpleDateFormat("MM");
        SimpleDateFormat sdf3 = new SimpleDateFormat("dd");

        String root_path = GlobalConfig.web_server_root_path;
        String save_folder = "qrcode/" + sdf1.format(calendar.getTime()) + "/" + sdf2.format(calendar.getTime()) + "/" + sdf3.format(calendar.getTime());

        // 10天前
        String path_delete_1 = root_path + save_folder;

        calendar.add(Calendar.DAY_OF_MONTH, 1);
        save_folder = "qrcode/" + sdf1.format(calendar.getTime()) + "/" + sdf2.format(calendar.getTime()) + "/" + sdf3.format(calendar.getTime());
        // 9天前
        String path_delete_2 = root_path + save_folder;

        calendar.add(Calendar.DAY_OF_MONTH, 1);
        save_folder = "qrcode/" + sdf1.format(calendar.getTime()) + "/" + sdf2.format(calendar.getTime()) + "/" + sdf3.format(calendar.getTime());
        // 8天前
        String path_delete_3 = root_path + save_folder;

        try
        {
            CM.deletefile(path_delete_1);
        } catch (Exception e)
        {
            e.printStackTrace();
        }
        try
        {
            CM.deletefile(path_delete_2);
        } catch (Exception e)
        {
            e.printStackTrace();
        }
        try
        {
            CM.deletefile(path_delete_3);
        } catch (Exception e)
        {
            e.printStackTrace();
        }
        System.out.println("批量删除过期的临时二维码图片，利用临时二维码保存的带有时间标记的文件夹来删除--结束");
    }

    private void batch_export_goods_excel_file()
    {
        System.out.println("生成全部商品列表Excel--开始");
        // 生成全部商品列表Excel
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String goods_export_file_path = GlobalConfig.web_server_root_path + "file/" + GlobalConfig.goods_export_excel_file_name;
        try
        {
            FileOutputStream goods_output = new FileOutputStream(new File(goods_export_file_path));
            // 内存中保留 100条数据，以免内存溢出，其余写入硬盘
            SXSSFWorkbook goods_wb = new SXSSFWorkbook(100);
            Sheet goods_sheet = goods_wb.createSheet("Sheet 1");

            Row goods_row = goods_sheet.createRow(0);

            CellStyle style_title = goods_wb.createCellStyle();
            style_title.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.index);
            style_title.setFillPattern(CellStyle.SOLID_FOREGROUND);
            style_title.setBorderBottom(CellStyle.BORDER_THIN); // 下边框
            style_title.setBorderLeft(CellStyle.BORDER_THIN);// 左边框
            style_title.setBorderTop(CellStyle.BORDER_THIN);// 上边框
            style_title.setBorderRight(CellStyle.BORDER_THIN);// 右边框
            style_title.setAlignment(CellStyle.ALIGN_CENTER);// 居中

            CellStyle style_content = goods_wb.createCellStyle();
            style_content.setBorderBottom(CellStyle.BORDER_THIN); // 下边框
            style_content.setBorderLeft(CellStyle.BORDER_THIN);// 左边框
            style_content.setBorderTop(CellStyle.BORDER_THIN);// 上边框
            style_content.setBorderRight(CellStyle.BORDER_THIN);// 右边框

            // 商品类型
            Cell cell = goods_row.createCell(0);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("商品类型");
            cell.setCellStyle(style_title);
            // 商品编号
            cell = goods_row.createCell(1);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("商品编号");
            cell.setCellStyle(style_title);
            // 商品名称
            cell = goods_row.createCell(2);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("商品名称");
            cell.setCellStyle(style_title);
            // 商品价格
            cell = goods_row.createCell(3);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("商品价格");
            cell.setCellStyle(style_title);
            // 商品佣金
            cell = goods_row.createCell(4);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("商品佣金");
            cell.setCellStyle(style_title);
            // 商品库存数量
            cell = goods_row.createCell(5);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("商品库存数量");
            cell.setCellStyle(style_title);
            // 商品原价格
            cell = goods_row.createCell(6);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("商品原价格");
            cell.setCellStyle(style_title);
            // 商品折扣
            cell = goods_row.createCell(7);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("商品折扣");
            cell.setCellStyle(style_title);
            // 最少购买件数
            cell = goods_row.createCell(8);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("最少购买件数");
            cell.setCellStyle(style_title);
            // 商品品牌
            cell = goods_row.createCell(9);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("商品品牌");
            cell.setCellStyle(style_title);
            // 商品货号
            cell = goods_row.createCell(10);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("商品货号");
            cell.setCellStyle(style_title);
            // 商品提示
            cell = goods_row.createCell(11);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("商品提示");
            cell.setCellStyle(style_title);
            // 商品添加时间
            cell = goods_row.createCell(12);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("商品添加时间");
            cell.setCellStyle(style_title);
            // 商品更新时间
            cell = goods_row.createCell(13);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("商品更新时间");
            cell.setCellStyle(style_title);
            // 商品状态
            cell = goods_row.createCell(14);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("商品状态");
            cell.setCellStyle(style_title);

            int the_whole_goods_countInDB = goodsDAO.getGoodsTotalCount();
            int one_page_size_of_whole_goods = 100;
            if (the_whole_goods_countInDB > 0)
            {
                int ttpTemp = the_whole_goods_countInDB % one_page_size_of_whole_goods == 0 ? the_whole_goods_countInDB / one_page_size_of_whole_goods : the_whole_goods_countInDB / one_page_size_of_whole_goods + 1;
                for (int i = 1; i <= ttpTemp; i++)
                {
                    List<Goods> goodsList = goodsDAO.getListByIndexAndPageSize(i, one_page_size_of_whole_goods);
                    if (goodsList != null && goodsList.size() > 0)
                    {
                        for (int j = 0; j < goodsList.size(); j++)
                        {
                            Goods temp_goods = goodsList.get(j);
                            goods_row = goods_sheet.createRow((i - 1) * one_page_size_of_whole_goods + j + 1);

                            // 商品类型
                            cell = goods_row.createCell(0);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(CM.getGoodsTypeStrByTypeId(temp_goods.getGoodsTypeId()));
                            cell.setCellStyle(style_content);
                            // 商品编号
                            cell = goods_row.createCell(1);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_goods.getGoodsId());
                            cell.setCellStyle(style_content);
                            // 商品名称
                            cell = goods_row.createCell(2);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_goods.getGoodsName());
                            cell.setCellStyle(style_content);
                            // 商品价格
                            cell = goods_row.createCell(3);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(String.valueOf(temp_goods.getGoodsPrice()));
                            cell.setCellStyle(style_content);
                            // 商品佣金
                            cell = goods_row.createCell(4);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(String.valueOf(temp_goods.getGoodsCommission()));
                            cell.setCellStyle(style_content);
                            // 商品库存数量
                            cell = goods_row.createCell(5);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(String.valueOf(temp_goods.getGoodsInventoryNumber()));
                            cell.setCellStyle(style_content);
                            // 商品原价格
                            cell = goods_row.createCell(6);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_goods.getGoodsOriginalPrice() == null ? "" : String.valueOf(temp_goods.getGoodsOriginalPrice()));
                            cell.setCellStyle(style_content);
                            // 商品折扣
                            cell = goods_row.createCell(7);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_goods.getGoodsDiscount() == null ? "" : String.valueOf(temp_goods.getGoodsDiscount()));
                            cell.setCellStyle(style_content);
                            // 最少购买件数
                            cell = goods_row.createCell(8);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_goods.getGoodsMinBuyNumber() == null ? "" : String.valueOf(temp_goods.getGoodsMinBuyNumber()));
                            cell.setCellStyle(style_content);
                            // 商品品牌
                            cell = goods_row.createCell(9);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_goods.getGoodsBrand() == null ? "" : temp_goods.getGoodsBrand());
                            cell.setCellStyle(style_content);
                            // 商品货号
                            cell = goods_row.createCell(10);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_goods.getGoodsItemId() == null ? "" : temp_goods.getGoodsItemId());
                            cell.setCellStyle(style_content);
                            // 商品提示
                            cell = goods_row.createCell(11);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_goods.getGoodsTips() == null ? "" : temp_goods.getGoodsTips());
                            cell.setCellStyle(style_content);
                            // 商品添加时间
                            cell = goods_row.createCell(12);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(sdf.format(temp_goods.getGoodsStartTime()));
                            cell.setCellStyle(style_content);
                            // 商品更新时间
                            cell = goods_row.createCell(13);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(sdf.format(temp_goods.getGoodsUpdateTime()));
                            cell.setCellStyle(style_content);
                            // 商品状态
                            cell = goods_row.createCell(14);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_goods.getGoodsStatus());
                            cell.setCellStyle(style_content);
                        }
                    }
                }
            }
            goods_wb.write(goods_output);
            goods_output.close();
        } catch (IOException e)
        {
            e.printStackTrace();
        }

        System.out.println("生成全部商品列表Excel--结束");
    }

    private void batch_export_buyer_excel_file()
    {
        System.out.println("生成全部买家列表Excel--开始");
        // 生成全部买家列表Excel
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String buyer_export_file_path = GlobalConfig.web_server_root_path + "file/" + GlobalConfig.buyer_export_excel_file_name;
        try
        {
            FileOutputStream buyer_output = new FileOutputStream(new File(buyer_export_file_path));
            // 内存中保留 100条数据，以免内存溢出，其余写入硬盘
            SXSSFWorkbook buyer_wb = new SXSSFWorkbook(100);
            Sheet buyer_sheet = buyer_wb.createSheet("Sheet 1");

            Row buyer_row = buyer_sheet.createRow(0);

            CellStyle style_title = buyer_wb.createCellStyle();
            style_title.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.index);
            style_title.setFillPattern(CellStyle.SOLID_FOREGROUND);
            style_title.setBorderBottom(CellStyle.BORDER_THIN); // 下边框
            style_title.setBorderLeft(CellStyle.BORDER_THIN);// 左边框
            style_title.setBorderTop(CellStyle.BORDER_THIN);// 上边框
            style_title.setBorderRight(CellStyle.BORDER_THIN);// 右边框
            style_title.setAlignment(CellStyle.ALIGN_CENTER);// 居中

            CellStyle style_content = buyer_wb.createCellStyle();
            style_content.setBorderBottom(CellStyle.BORDER_THIN); // 下边框
            style_content.setBorderLeft(CellStyle.BORDER_THIN);// 左边框
            style_content.setBorderTop(CellStyle.BORDER_THIN);// 上边框
            style_content.setBorderRight(CellStyle.BORDER_THIN);// 右边框

            // 买家编号
            Cell cell = buyer_row.createCell(0);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("买家编号");
            cell.setCellStyle(style_title);
            // 买家名称
            cell = buyer_row.createCell(1);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("买家名称");
            cell.setCellStyle(style_title);
            // 买家昵称
            cell = buyer_row.createCell(2);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("买家昵称");
            cell.setCellStyle(style_title);
            // 买家地区
            cell = buyer_row.createCell(3);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("买家地区");
            cell.setCellStyle(style_title);
            // 买家性别
            cell = buyer_row.createCell(4);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("买家性别");
            cell.setCellStyle(style_title);
            // 买家真实姓名
            cell = buyer_row.createCell(5);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("买家真实姓名");
            cell.setCellStyle(style_title);
            // 买家类型
            cell = buyer_row.createCell(6);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("买家类型");
            cell.setCellStyle(style_title);
            // 买家状态
            cell = buyer_row.createCell(7);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("买家状态");
            cell.setCellStyle(style_title);
            // 买家注册时间
            cell = buyer_row.createCell(8);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("买家注册时间");
            cell.setCellStyle(style_title);
            // 介绍人编号
            cell = buyer_row.createCell(9);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("介绍人编号");
            cell.setCellStyle(style_title);
            // 介绍人昵称
            cell = buyer_row.createCell(10);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("介绍人昵称");
            cell.setCellStyle(style_title);

            int the_whole_buyer_countInDB = buyerDAO.getTotalCountBy_keyword(null);
            int one_page_size_of_whole_buyer = 100;
            if (the_whole_buyer_countInDB > 0)
            {
                int ttpTemp = the_whole_buyer_countInDB % one_page_size_of_whole_buyer == 0 ? the_whole_buyer_countInDB / one_page_size_of_whole_buyer : the_whole_buyer_countInDB / one_page_size_of_whole_buyer + 1;
                for (int i = 1; i <= ttpTemp; i++)
                {
                    List<Buyer> buyerList = buyerDAO.getListByIndexAndPageSizeAnd_keyword(i, one_page_size_of_whole_buyer, null);
                    if (buyerList != null && buyerList.size() > 0)
                    {
                        for (int j = 0; j < buyerList.size(); j++)
                        {
                            Buyer temp_buyer = buyerList.get(j);
                            buyer_row = buyer_sheet.createRow((i - 1) * one_page_size_of_whole_buyer + j + 1);

                            // 买家编号
                            cell = buyer_row.createCell(0);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_buyer.getBuyerId());
                            cell.setCellStyle(style_content);
                            // 买家名称
                            cell = buyer_row.createCell(1);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_buyer.getBuyerName() == null ? "" : temp_buyer.getBuyerName());
                            cell.setCellStyle(style_content);
                            // 买家昵称
                            cell = buyer_row.createCell(2);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_buyer.getBuyerNickname() == null ? "" : temp_buyer.getBuyerNickname());
                            cell.setCellStyle(style_content);
                            // 买家地区
                            cell = buyer_row.createCell(3);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue((temp_buyer.getBuyerCountry() == null ? "" : temp_buyer.getBuyerCountry()) + (temp_buyer.getBuyerProvince() == null ? "" : temp_buyer.getBuyerProvince()) + (temp_buyer.getBuyerCity() == null ? "" : temp_buyer.getBuyerCity()));
                            cell.setCellStyle(style_content);

                            // 买家性别
                            cell = buyer_row.createCell(4);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_buyer.getBuyerSex() == null ? "" : CM.getSexFromWechatNumber(temp_buyer.getBuyerSex()));
                            cell.setCellStyle(style_content);
                            // 买家真实姓名
                            cell = buyer_row.createCell(5);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_buyer.getBuyerRealName() == null ? "" : temp_buyer.getBuyerRealName());
                            cell.setCellStyle(style_content);
                            // 买家类型
                            cell = buyer_row.createCell(6);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_buyer.getBuyerType() == null ? "" : temp_buyer.getBuyerType());
                            cell.setCellStyle(style_content);
                            // 买家状态
                            cell = buyer_row.createCell(7);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_buyer.getBuyerStatus() == null ? "" : temp_buyer.getBuyerStatus());
                            cell.setCellStyle(style_content);
                            // 买家注册时间
                            cell = buyer_row.createCell(8);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(sdf.format(temp_buyer.getBuyerRegisterTime()));
                            cell.setCellStyle(style_content);

                            if (temp_buyer.getBuyerIntroducer() == null)
                            {
                                // 介绍人编号
                                cell = buyer_row.createCell(9);
                                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                cell.setCellValue("");
                                cell.setCellStyle(style_content);
                                // 介绍人昵称
                                cell = buyer_row.createCell(10);
                                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                cell.setCellValue("");
                                cell.setCellStyle(style_content);
                            }
                            else
                            {
                                Buyer buyerIntroducerFromDB = buyerDAO.findById(temp_buyer.getBuyerIntroducer());
                                if (buyerIntroducerFromDB == null)
                                {
                                    // 介绍人编号
                                    cell = buyer_row.createCell(9);
                                    cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                    cell.setCellValue("");
                                    cell.setCellStyle(style_content);
                                    // 介绍人昵称
                                    cell = buyer_row.createCell(10);
                                    cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                    cell.setCellValue("");
                                    cell.setCellStyle(style_content);
                                }
                                else
                                {
                                    // 介绍人编号
                                    cell = buyer_row.createCell(9);
                                    cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                    cell.setCellValue(buyerIntroducerFromDB.getBuyerId());
                                    cell.setCellStyle(style_content);
                                    // 介绍人昵称
                                    cell = buyer_row.createCell(10);
                                    cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                    cell.setCellValue(buyerIntroducerFromDB.getBuyerNickname() == null ? "" : buyerIntroducerFromDB.getBuyerNickname());
                                    cell.setCellStyle(style_content);
                                }

                            }

                        }
                    }
                }
            }
            buyer_wb.write(buyer_output);
            buyer_output.close();
        } catch (IOException e)
        {
            e.printStackTrace();
        }

        System.out.println("生成全部买家列表Excel--结束");
    }

    private void batch_export_buyer_report_file()
    {
        System.out.println("生成买家每周报表Excel--开始");

        Date[] dateArray = CM.getMonthReportStartDateAndEndDate(Calendar.getInstance().getTime());
        Date month_start_date = dateArray[0];
        Date month_end_date = dateArray[1];
        // 生成全部买家列表Excel
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String buyer_export_file_path = GlobalConfig.web_server_root_path + "file/report/" + GlobalConfig.buyer_export_report_file_name;
        buyer_export_file_path = buyer_export_file_path.replaceAll(".xlsx", "_" + sdf_month.format(month_start_date) + ".xlsx");
        try
        {
            FileOutputStream buyer_output = new FileOutputStream(new File(buyer_export_file_path));
            // 内存中保留 100条数据，以免内存溢出，其余写入硬盘
            SXSSFWorkbook buyer_wb = new SXSSFWorkbook(100);
            Sheet buyer_sheet = buyer_wb.createSheet("Sheet 1");

            Row buyer_row = buyer_sheet.createRow(0);

            CellStyle style_title = buyer_wb.createCellStyle();
            style_title.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.index);
            style_title.setFillPattern(CellStyle.SOLID_FOREGROUND);
            style_title.setBorderBottom(CellStyle.BORDER_THIN); // 下边框
            style_title.setBorderLeft(CellStyle.BORDER_THIN);// 左边框
            style_title.setBorderTop(CellStyle.BORDER_THIN);// 上边框
            style_title.setBorderRight(CellStyle.BORDER_THIN);// 右边框
            style_title.setAlignment(CellStyle.ALIGN_CENTER);// 居中

            CellStyle style_content = buyer_wb.createCellStyle();
            style_content.setBorderBottom(CellStyle.BORDER_THIN); // 下边框
            style_content.setBorderLeft(CellStyle.BORDER_THIN);// 左边框
            style_content.setBorderTop(CellStyle.BORDER_THIN);// 上边框
            style_content.setBorderRight(CellStyle.BORDER_THIN);// 右边框

            CellStyle style_content_highlight = buyer_wb.createCellStyle();
            style_content_highlight.setFillForegroundColor(IndexedColors.YELLOW.index);
            style_content_highlight.setFillPattern(CellStyle.SOLID_FOREGROUND);
            style_content_highlight.setBorderBottom(CellStyle.BORDER_THIN); // 下边框
            style_content_highlight.setBorderLeft(CellStyle.BORDER_THIN);// 左边框
            style_content_highlight.setBorderTop(CellStyle.BORDER_THIN);// 上边框
            style_content_highlight.setBorderRight(CellStyle.BORDER_THIN);// 右边框

            // 报告日期
            Cell cell = buyer_row.createCell(0);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("报告周次");
            cell.setCellStyle(style_title);
            // 买家编号
            cell = buyer_row.createCell(1);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("买家编号");
            cell.setCellStyle(style_title);
            // 买家名称
            cell = buyer_row.createCell(2);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("买家名称");
            cell.setCellStyle(style_title);
            // 买家昵称
            cell = buyer_row.createCell(3);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("买家昵称");
            cell.setCellStyle(style_title);
            // 买家地区
            cell = buyer_row.createCell(4);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("买家地区");
            cell.setCellStyle(style_title);
            // 买家性别
            cell = buyer_row.createCell(5);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("买家性别");
            cell.setCellStyle(style_title);
            // 买家真实姓名
            cell = buyer_row.createCell(6);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("买家真实姓名");
            cell.setCellStyle(style_title);
            // 买家类型
            cell = buyer_row.createCell(7);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("买家类型");
            cell.setCellStyle(style_title);
            // 买家状态
            cell = buyer_row.createCell(8);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("买家状态");
            cell.setCellStyle(style_title);
            // 买家注册时间
            cell = buyer_row.createCell(9);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("买家注册时间");
            cell.setCellStyle(style_title);
            // 介绍人编号
            cell = buyer_row.createCell(10);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("介绍人编号");
            cell.setCellStyle(style_title);
            // 介绍人昵称
            cell = buyer_row.createCell(11);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("介绍人昵称");
            cell.setCellStyle(style_title);

            int the_whole_buyer_countInDB = buyerDAO.getTotalCountByBeginTimeAndEndTime(month_start_date, month_end_date);
            int one_page_size_of_whole_buyer = 100;
            if (the_whole_buyer_countInDB > 0)
            {
                int ttpTemp = the_whole_buyer_countInDB % one_page_size_of_whole_buyer == 0 ? the_whole_buyer_countInDB / one_page_size_of_whole_buyer : the_whole_buyer_countInDB / one_page_size_of_whole_buyer + 1;
                for (int i = 1; i <= ttpTemp; i++)
                {
                    List<Buyer> buyerList = buyerDAO.getListByIndexAndPageSizeAndBeginTimeAndEndTime(i, one_page_size_of_whole_buyer, month_start_date, month_end_date);
                    if (buyerList != null && buyerList.size() > 0)
                    {
                        for (int j = 0; j < buyerList.size(); j++)
                        {
                            Buyer temp_buyer = buyerList.get(j);
                            buyer_row = buyer_sheet.createRow((i - 1) * one_page_size_of_whole_buyer + j + 1);

                            // 报告日期
                            cell = buyer_row.createCell(0);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(CM.getWeekStringByDate(temp_buyer.getBuyerRegisterTime()));
                            cell.setCellStyle(CM.validWeekHighlight(temp_buyer.getBuyerRegisterTime()) ? style_content_highlight : style_content);
                            // 买家编号
                            cell = buyer_row.createCell(1);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_buyer.getBuyerId());
                            cell.setCellStyle(style_content);
                            // 买家名称
                            cell = buyer_row.createCell(2);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_buyer.getBuyerName() == null ? "" : temp_buyer.getBuyerName());
                            cell.setCellStyle(style_content);
                            // 买家昵称
                            cell = buyer_row.createCell(3);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_buyer.getBuyerNickname() == null ? "" : temp_buyer.getBuyerNickname());
                            cell.setCellStyle(style_content);
                            // 买家地区
                            cell = buyer_row.createCell(4);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue((temp_buyer.getBuyerCountry() == null ? "" : temp_buyer.getBuyerCountry()) + (temp_buyer.getBuyerProvince() == null ? "" : temp_buyer.getBuyerProvince()) + (temp_buyer.getBuyerCity() == null ? "" : temp_buyer.getBuyerCity()));
                            cell.setCellStyle(style_content);

                            // 买家性别
                            cell = buyer_row.createCell(5);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_buyer.getBuyerSex() == null ? "" : CM.getSexFromWechatNumber(temp_buyer.getBuyerSex()));
                            cell.setCellStyle(style_content);
                            // 买家真实姓名
                            cell = buyer_row.createCell(6);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_buyer.getBuyerRealName() == null ? "" : temp_buyer.getBuyerRealName());
                            cell.setCellStyle(style_content);
                            // 买家类型
                            cell = buyer_row.createCell(7);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_buyer.getBuyerType() == null ? "" : temp_buyer.getBuyerType());
                            cell.setCellStyle(style_content);
                            // 买家状态
                            cell = buyer_row.createCell(8);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_buyer.getBuyerStatus() == null ? "" : temp_buyer.getBuyerStatus());
                            cell.setCellStyle(style_content);
                            // 买家注册时间
                            cell = buyer_row.createCell(9);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(sdf.format(temp_buyer.getBuyerRegisterTime()));
                            cell.setCellStyle(style_content);

                            if (temp_buyer.getBuyerIntroducer() == null)
                            {
                                // 介绍人编号
                                cell = buyer_row.createCell(10);
                                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                cell.setCellValue("");
                                cell.setCellStyle(style_content);
                                // 介绍人昵称
                                cell = buyer_row.createCell(11);
                                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                cell.setCellValue("");
                                cell.setCellStyle(style_content);
                            }
                            else
                            {
                                Buyer buyerIntroducerFromDB = buyerDAO.findById(temp_buyer.getBuyerIntroducer());
                                if (buyerIntroducerFromDB == null)
                                {
                                    // 介绍人编号
                                    cell = buyer_row.createCell(10);
                                    cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                    cell.setCellValue("");
                                    cell.setCellStyle(style_content);
                                    // 介绍人昵称
                                    cell = buyer_row.createCell(11);
                                    cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                    cell.setCellValue("");
                                    cell.setCellStyle(style_content);
                                }
                                else
                                {
                                    // 介绍人编号
                                    cell = buyer_row.createCell(10);
                                    cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                    cell.setCellValue(buyerIntroducerFromDB.getBuyerId());
                                    cell.setCellStyle(style_content);
                                    // 介绍人昵称
                                    cell = buyer_row.createCell(11);
                                    cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                    cell.setCellValue(buyerIntroducerFromDB.getBuyerNickname() == null ? "" : buyerIntroducerFromDB.getBuyerNickname());
                                    cell.setCellStyle(style_content);
                                }

                            }

                        }
                    }
                }
            }
            buyer_wb.write(buyer_output);
            buyer_output.close();
        } catch (IOException e)
        {
            e.printStackTrace();
        }

        System.out.println("生成买家每周报表Excel--结束");
    }

    private void batch_export_order_return_report_file()
    {
        System.out.println("生成每周退换货报表Excel--开始");

        Date[] dateArray = CM.getMonthReportStartDateAndEndDate(Calendar.getInstance().getTime());
        Date month_start_date = dateArray[0];
        Date month_end_date = dateArray[1];
        // 生成全部退换货列表Excel
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String order_return_export_file_path = GlobalConfig.web_server_root_path + "file/report/" + GlobalConfig.order_return_export_report_file_name;
        order_return_export_file_path = order_return_export_file_path.replaceAll(".xlsx", "_" + sdf_month.format(month_start_date) + ".xlsx");
        try
        {
            FileOutputStream orderReturn_output = new FileOutputStream(new File(order_return_export_file_path));
            // 内存中保留 100条数据，以免内存溢出，其余写入硬盘
            SXSSFWorkbook orderReturn_wb = new SXSSFWorkbook(100);
            Sheet orderReturn_sheet = orderReturn_wb.createSheet("Sheet 1");

            Row orderReturn_row = orderReturn_sheet.createRow(0);

            CellStyle style_title = orderReturn_wb.createCellStyle();
            style_title.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.index);
            style_title.setFillPattern(CellStyle.SOLID_FOREGROUND);
            style_title.setBorderBottom(CellStyle.BORDER_THIN); // 下边框
            style_title.setBorderLeft(CellStyle.BORDER_THIN);// 左边框
            style_title.setBorderTop(CellStyle.BORDER_THIN);// 上边框
            style_title.setBorderRight(CellStyle.BORDER_THIN);// 右边框
            style_title.setAlignment(CellStyle.ALIGN_CENTER);// 居中

            CellStyle style_content = orderReturn_wb.createCellStyle();
            style_content.setBorderBottom(CellStyle.BORDER_THIN); // 下边框
            style_content.setBorderLeft(CellStyle.BORDER_THIN);// 左边框
            style_content.setBorderTop(CellStyle.BORDER_THIN);// 上边框
            style_content.setBorderRight(CellStyle.BORDER_THIN);// 右边框

            CellStyle style_content_highlight = orderReturn_wb.createCellStyle();
            style_content_highlight.setFillForegroundColor(IndexedColors.YELLOW.index);
            style_content_highlight.setFillPattern(CellStyle.SOLID_FOREGROUND);
            style_content_highlight.setBorderBottom(CellStyle.BORDER_THIN); // 下边框
            style_content_highlight.setBorderLeft(CellStyle.BORDER_THIN);// 左边框
            style_content_highlight.setBorderTop(CellStyle.BORDER_THIN);// 上边框
            style_content_highlight.setBorderRight(CellStyle.BORDER_THIN);// 右边框

            CellStyle style_content_light = orderReturn_wb.createCellStyle();
            style_content_light.setBorderBottom(CellStyle.BORDER_THIN); // 下边框
            style_content_light.setBorderLeft(CellStyle.BORDER_THIN);// 左边框
            style_content_light.setBorderTop(CellStyle.BORDER_THIN);// 上边框
            style_content_light.setBorderRight(CellStyle.BORDER_THIN);// 右边框
            Font font_light = orderReturn_wb.createFont();
            font_light.setFontName("宋体");
            font_light.setColor(IndexedColors.GREY_40_PERCENT.index);
            style_content_light.setFont(font_light);// 设置字体颜色

            // 报告日期
            Cell cell = orderReturn_row.createCell(0);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("报告周次");
            cell.setCellStyle(style_title);
            // 退换货编号
            cell = orderReturn_row.createCell(1);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("退换货编号");
            cell.setCellStyle(style_title);
            // 订单编号
            cell = orderReturn_row.createCell(2);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("订单编号");
            cell.setCellStyle(style_title);
            // 退换货时间
            cell = orderReturn_row.createCell(3);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("退换货时间");
            cell.setCellStyle(style_title);
            // 付款总额
            cell = orderReturn_row.createCell(4);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("付款总额");
            cell.setCellStyle(style_title);
            // 退换货类型
            cell = orderReturn_row.createCell(5);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("退换货类型");
            cell.setCellStyle(style_title);
            // 退换货状态
            cell = orderReturn_row.createCell(6);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("退换货状态");
            cell.setCellStyle(style_title);
            // 退换货原因
            cell = orderReturn_row.createCell(7);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("退换货原因");
            cell.setCellStyle(style_title);
            // 收货人
            cell = orderReturn_row.createCell(8);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("收货人");
            cell.setCellStyle(style_title);
            // 收货人电话号码
            cell = orderReturn_row.createCell(9);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("收货人电话号码");
            cell.setCellStyle(style_title);
            // 收货地址
            cell = orderReturn_row.createCell(10);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("收货地址");
            cell.setCellStyle(style_title);

            int the_whole_order_return_countInDB = orderReturnDAO.getTotalCountByBeginTimeAndEndTime(month_start_date, month_end_date);
            int one_page_size_of_whole_order_return = 100;

            // 设置row_index
            int row_index = 1;
            if (the_whole_order_return_countInDB > 0)
            {
                int ttpTemp = the_whole_order_return_countInDB % one_page_size_of_whole_order_return == 0 ? the_whole_order_return_countInDB / one_page_size_of_whole_order_return : the_whole_order_return_countInDB / one_page_size_of_whole_order_return + 1;
                for (int i = 1; i <= ttpTemp; i++)
                {
                    List<OrderReturn> orderReturnList = orderReturnDAO.getListByIndexAndPageSizeAndBeginTimeAndEndTime(i, one_page_size_of_whole_order_return, month_start_date, month_end_date);
                    if (orderReturnList != null && orderReturnList.size() > 0)
                    {
                        for (int j = 0; j < orderReturnList.size(); j++)
                        {
                            OrderReturn temp_orderReturn = orderReturnList.get(j);
                            orderReturn_row = orderReturn_sheet.createRow(row_index);
                            row_index++;

                            // 报告周次
                            cell = orderReturn_row.createCell(0);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(CM.getWeekStringByDate(temp_orderReturn.getOrderReturnBeginTime()));
                            cell.setCellStyle(CM.validWeekHighlight(temp_orderReturn.getOrderReturnBeginTime()) ? style_content_highlight : style_content);
                            // 退换货编号
                            cell = orderReturn_row.createCell(1);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_orderReturn.getOrderReturnId());
                            cell.setCellStyle(style_content);
                            // 订单编号
                            cell = orderReturn_row.createCell(2);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_orderReturn.getOrderId());
                            cell.setCellStyle(style_content);
                            // 退换货时间
                            cell = orderReturn_row.createCell(3);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(sdf.format(temp_orderReturn.getOrderReturnBeginTime()));
                            cell.setCellStyle(style_content);

                            // 得到退换货所在的订单
                            Order orderFromDB = orderDAO.findById(temp_orderReturn.getOrderId());
                            if (orderFromDB == null)
                            {
                                continue;
                            }

                            // 付款总额
                            cell = orderReturn_row.createCell(4);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(String.valueOf(orderFromDB.getOrderTotalPrice()));
                            cell.setCellStyle(style_content);

                            // 退换货类型
                            cell = orderReturn_row.createCell(5);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_orderReturn.getOrderReturnType());
                            cell.setCellStyle(style_content);
                            // 退换货状态
                            cell = orderReturn_row.createCell(6);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_orderReturn.getOrderReturnStatus());
                            cell.setCellStyle(style_content);
                            // 退换货原因
                            cell = orderReturn_row.createCell(7);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_orderReturn.getOrderReturnReason());
                            cell.setCellStyle(style_content);
                            // 收货人
                            cell = orderReturn_row.createCell(8);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(orderFromDB.getOrderBuyerName() == null ? "" : orderFromDB.getOrderBuyerName());
                            cell.setCellStyle(style_content);
                            // 收货人电话号码
                            cell = orderReturn_row.createCell(9);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(orderFromDB.getOrderBuyerPhone() == null ? "" : orderFromDB.getOrderBuyerPhone());
                            cell.setCellStyle(style_content);
                            // 收货地址
                            cell = orderReturn_row.createCell(10);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(orderFromDB.getOrderBuyerAddress() == null ? "" : orderFromDB.getOrderBuyerAddress());
                            cell.setCellStyle(style_content);

                            List<OrderGoods> orderGoodList = orderGoodsDAO.findByOrderId(temp_orderReturn.getOrderId());
                            if (orderGoodList == null || orderGoodList.size() == 0)
                            {
                                continue;
                            }

                            int goods_index = 1;
                            for (OrderGoods ogTemp : orderGoodList)
                            {
                                Goods goodsFromDB = goodsDAO.findById(ogTemp.getGoodsId());
                                if (goodsFromDB == null)
                                {
                                    continue;
                                }

                                orderReturn_row = orderReturn_sheet.createRow(row_index);
                                row_index++;
                                // 首列
                                cell = orderReturn_row.createCell(0);
                                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                cell.setCellValue("");
                                cell.setCellStyle(CM.validWeekHighlight(temp_orderReturn.getOrderReturnBeginTime()) ? style_content_highlight : style_content);
                                // 退换货包含商品
                                cell = orderReturn_row.createCell(1);
                                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                cell.setCellValue("退换货包含商品" + goods_index);
                                goods_index++;
                                cell.setCellStyle(style_content_light);
                                // 商品编号
                                cell = orderReturn_row.createCell(2);
                                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                cell.setCellValue(goodsFromDB.getGoodsId() + "(商品编号)");
                                cell.setCellStyle(style_content_light);
                                // 商品名称
                                cell = orderReturn_row.createCell(3);
                                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                cell.setCellValue(goodsFromDB.getGoodsName() + "(商品名称)");
                                cell.setCellStyle(style_content_light);
                                // 商品单价
                                cell = orderReturn_row.createCell(4);
                                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                cell.setCellValue(goodsFromDB.getGoodsPrice() + "(商品单价)");
                                cell.setCellStyle(style_content_light);
                                // 商品数量
                                cell = orderReturn_row.createCell(5);
                                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                cell.setCellValue(ogTemp.getGoodsNumber() + "(商品数量)");
                                cell.setCellStyle(style_content_light);

                            }
                        }
                    }
                }
            }
            orderReturn_wb.write(orderReturn_output);
            orderReturn_output.close();
        } catch (IOException e)
        {
            e.printStackTrace();
        }

        System.out.println("生成每周退换货报表Excel--结束");
    }

    private void batch_export_order_report_file()
    {
        System.out.println("生成每周订单报表Excel--开始");

        Date[] dateArray = CM.getMonthReportStartDateAndEndDate(Calendar.getInstance().getTime());
        Date month_start_date = dateArray[0];
        Date month_end_date = dateArray[1];
        // 生成全部退换货列表Excel
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String order_export_file_path = GlobalConfig.web_server_root_path + "file/report/" + GlobalConfig.order_export_report_file_name;
        order_export_file_path = order_export_file_path.replaceAll(".xlsx", "_" + sdf_month.format(month_start_date) + ".xlsx");
        try
        {
            FileOutputStream order_output = new FileOutputStream(new File(order_export_file_path));
            // 内存中保留 100条数据，以免内存溢出，其余写入硬盘
            SXSSFWorkbook order_wb = new SXSSFWorkbook(100);
            Sheet order_sheet = order_wb.createSheet("Sheet 1");

            Row order_row = order_sheet.createRow(0);

            CellStyle style_title = order_wb.createCellStyle();
            style_title.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.index);
            style_title.setFillPattern(CellStyle.SOLID_FOREGROUND);
            style_title.setBorderBottom(CellStyle.BORDER_THIN); // 下边框
            style_title.setBorderLeft(CellStyle.BORDER_THIN);// 左边框
            style_title.setBorderTop(CellStyle.BORDER_THIN);// 上边框
            style_title.setBorderRight(CellStyle.BORDER_THIN);// 右边框
            style_title.setAlignment(CellStyle.ALIGN_CENTER);// 居中

            CellStyle style_content = order_wb.createCellStyle();
            style_content.setBorderBottom(CellStyle.BORDER_THIN); // 下边框
            style_content.setBorderLeft(CellStyle.BORDER_THIN);// 左边框
            style_content.setBorderTop(CellStyle.BORDER_THIN);// 上边框
            style_content.setBorderRight(CellStyle.BORDER_THIN);// 右边框

            CellStyle style_content_highlight = order_wb.createCellStyle();
            style_content_highlight.setFillForegroundColor(IndexedColors.YELLOW.index);
            style_content_highlight.setFillPattern(CellStyle.SOLID_FOREGROUND);
            style_content_highlight.setBorderBottom(CellStyle.BORDER_THIN); // 下边框
            style_content_highlight.setBorderLeft(CellStyle.BORDER_THIN);// 左边框
            style_content_highlight.setBorderTop(CellStyle.BORDER_THIN);// 上边框
            style_content_highlight.setBorderRight(CellStyle.BORDER_THIN);// 右边框

            CellStyle style_content_light = order_wb.createCellStyle();
            style_content_light.setBorderBottom(CellStyle.BORDER_THIN); // 下边框
            style_content_light.setBorderLeft(CellStyle.BORDER_THIN);// 左边框
            style_content_light.setBorderTop(CellStyle.BORDER_THIN);// 上边框
            style_content_light.setBorderRight(CellStyle.BORDER_THIN);// 右边框
            Font font_light = order_wb.createFont();
            font_light.setFontName("宋体");
            font_light.setColor(IndexedColors.GREY_40_PERCENT.index);
            style_content_light.setFont(font_light);// 设置字体颜色

            // 报告日期
            Cell cell = order_row.createCell(0);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("报告周次");
            cell.setCellStyle(style_title);
            // 订单编号
            cell = order_row.createCell(1);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("订单编号");
            cell.setCellStyle(style_title);
            // 订单创建时间
            cell = order_row.createCell(2);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("订单创建时间");
            cell.setCellStyle(style_title);
            // 订单付款时间
            cell = order_row.createCell(3);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("订单付款时间");
            cell.setCellStyle(style_title);
            // 付款总额
            cell = order_row.createCell(4);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("付款总额");
            cell.setCellStyle(style_title);
            // 订单状态
            cell = order_row.createCell(5);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("订单状态");
            cell.setCellStyle(style_title);
            // 买家编号
            cell = order_row.createCell(6);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("买家编号");
            cell.setCellStyle(style_content_highlight);
            // 买家昵称
            cell = order_row.createCell(7);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("买家昵称");
            cell.setCellStyle(style_content_highlight);
            // 真实姓名
            cell = order_row.createCell(8);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("真实姓名");
            cell.setCellStyle(style_content_highlight);
            // 身份证号
            cell = order_row.createCell(9);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("身份证号");
            cell.setCellStyle(style_content_highlight);
            // 派送方式
            cell = order_row.createCell(10);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("派送方式");
            cell.setCellStyle(style_title);
            // 收货人
            cell = order_row.createCell(11);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("收货人");
            cell.setCellStyle(style_title);
            // 收货人电话号码
            cell = order_row.createCell(12);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("收货人电话号码");
            cell.setCellStyle(style_title);
            // 收货地址
            cell = order_row.createCell(13);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("收货地址");
            cell.setCellStyle(style_title);
            // 海关审验
            cell = order_row.createCell(14);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("海关审验");
            cell.setCellStyle(style_title);
            // 快递单号
            cell = order_row.createCell(15);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("快递单号");
            cell.setCellStyle(style_title);
            // 快递公司
            cell = order_row.createCell(16);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("快递公司");
            cell.setCellStyle(style_title);

            int the_whole_order_countInDB = orderDAO.getTotalCountPayedOrderByBeginTimeAndEndTime(month_start_date, month_end_date);
            int one_page_size_of_whole_order = 100;

            // 设置row_index
            int row_index = 1;
            if (the_whole_order_countInDB > 0)
            {
                int ttpTemp = the_whole_order_countInDB % one_page_size_of_whole_order == 0 ? the_whole_order_countInDB / one_page_size_of_whole_order : the_whole_order_countInDB / one_page_size_of_whole_order + 1;
                for (int i = 1; i <= ttpTemp; i++)
                {
                    List<Order> orderList = orderDAO.getListPayedOrderByIndexAndPageSizeAndBeginTimeAndEndTime(i, one_page_size_of_whole_order, month_start_date, month_end_date);
                    if (orderList != null && orderList.size() > 0)
                    {
                        for (int j = 0; j < orderList.size(); j++)
                        {
                            Order temp_order = orderList.get(j);
                            order_row = order_sheet.createRow(row_index);
                            row_index++;

                            // 报告周次
                            cell = order_row.createCell(0);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(CM.getWeekStringByDate(temp_order.getOrderPayTime()));
                            cell.setCellStyle(CM.validWeekHighlight(temp_order.getOrderPayTime()) ? style_content_highlight : style_content);
                            // 订单编号
                            cell = order_row.createCell(1);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_order.getOrderId());
                            cell.setCellStyle(style_content);
                            // 订单创建时间
                            cell = order_row.createCell(2);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(sdf.format(temp_order.getOrderBuyTime()));
                            cell.setCellStyle(style_content);
                            // 订单付款时间
                            cell = order_row.createCell(3);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(sdf.format(temp_order.getOrderPayTime()));
                            cell.setCellStyle(style_content);
                            // 付款总额
                            cell = order_row.createCell(4);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(String.valueOf(temp_order.getOrderTotalPrice()));
                            cell.setCellStyle(style_content);
                            // 订单状态
                            cell = order_row.createCell(5);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_order.getOrderStatus());
                            cell.setCellStyle(style_content);

                            // 得到买家信息
                            Buyer buyerFromDB = buyerDAO.findById(temp_order.getBuyerId());
                            if (buyerFromDB == null)
                            {
                                continue;
                            }

                            // 买家编号
                            cell = order_row.createCell(6);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(buyerFromDB.getBuyerId());
                            cell.setCellStyle(style_content);
                            // 买家昵称
                            cell = order_row.createCell(7);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(buyerFromDB.getBuyerNickname() == null ? "" : buyerFromDB.getBuyerNickname());
                            cell.setCellStyle(style_content);
                            // 真实姓名
                            cell = order_row.createCell(8);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(buyerFromDB.getBuyerRealName() == null ? "" : buyerFromDB.getBuyerRealName());
                            cell.setCellStyle(style_content);
                            // 身份证号
                            cell = order_row.createCell(9);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(buyerFromDB.getBuyerPeopleId() == null ? "" : buyerFromDB.getBuyerPeopleId());
                            cell.setCellStyle(style_content);
                            // 派送方式
                            cell = order_row.createCell(10);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_order.getOrderSendWay() == null ? "" : temp_order.getOrderSendWay());
                            cell.setCellStyle(style_content);
                            // 收货人
                            cell = order_row.createCell(11);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_order.getOrderBuyerName() == null ? "" : temp_order.getOrderBuyerName());
                            cell.setCellStyle(style_content);
                            // 收货人电话号码
                            cell = order_row.createCell(12);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_order.getOrderBuyerPhone() == null ? "" : temp_order.getOrderBuyerPhone());
                            cell.setCellStyle(style_content);
                            // 收货地址
                            cell = order_row.createCell(13);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_order.getOrderBuyerAddress() == null ? "" : temp_order.getOrderBuyerAddress());
                            cell.setCellStyle(style_content);
                            // 海关审验
                            cell = order_row.createCell(14);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue("");
                            cell.setCellStyle(style_content);
                            // 快递单号
                            cell = order_row.createCell(15);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_order.getOrderExpressNumber() == null ? "" : temp_order.getOrderExpressNumber());
                            cell.setCellStyle(style_content);
                            // 快递单号
                            cell = order_row.createCell(16);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_order.getOrderExpressCompany() == null ? "" : temp_order.getOrderExpressCompany());
                            cell.setCellStyle(style_content);

                            List<OrderGoods> orderGoodList = orderGoodsDAO.findByOrderId(temp_order.getOrderId());
                            if (orderGoodList == null || orderGoodList.size() == 0)
                            {
                                continue;
                            }

                            int goods_index = 1;
                            for (OrderGoods ogTemp : orderGoodList)
                            {
                                Goods goodsFromDB = goodsDAO.findById(ogTemp.getGoodsId());
                                if (goodsFromDB == null)
                                {
                                    continue;
                                }

                                order_row = order_sheet.createRow(row_index);
                                row_index++;
                                // 首列
                                cell = order_row.createCell(0);
                                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                cell.setCellValue("");
                                cell.setCellStyle(CM.validWeekHighlight(temp_order.getOrderPayTime()) ? style_content_highlight : style_content);
                                // 退换货包含商品
                                cell = order_row.createCell(1);
                                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                cell.setCellValue("订单包含商品" + goods_index);
                                goods_index++;
                                cell.setCellStyle(style_content_light);
                                // 商品编号
                                cell = order_row.createCell(2);
                                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                cell.setCellValue(goodsFromDB.getGoodsId() + "(商品编号)");
                                cell.setCellStyle(style_content_light);
                                // 商品名称
                                cell = order_row.createCell(3);
                                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                cell.setCellValue(goodsFromDB.getGoodsName() + "(商品名称)");
                                cell.setCellStyle(style_content_light);
                                // 商品单价
                                cell = order_row.createCell(4);
                                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                cell.setCellValue(goodsFromDB.getGoodsPrice() + "(商品单价)");
                                cell.setCellStyle(style_content_light);
                                // 商品数量
                                cell = order_row.createCell(5);
                                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                cell.setCellValue(ogTemp.getGoodsNumber() + "(商品数量)");
                                cell.setCellStyle(style_content_light);

                            }
                        }
                    }
                }
            }
            order_wb.write(order_output);
            order_output.close();
        } catch (IOException e)
        {
            e.printStackTrace();
        }

        System.out.println("生成每周订单报表Excel--结束");
    }

    private void batch_export_commission_detail_report_file()
    {
        System.out.println("生成每周佣金明细报表Excel--开始");

        Date[] dateArray = CM.getMonthReportStartDateAndEndDate(Calendar.getInstance().getTime());
        Date month_start_date = dateArray[0];
        Date month_end_date = dateArray[1];
        // 生成全部退换货列表Excel
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String order_export_file_path = GlobalConfig.web_server_root_path + "file/report/" + GlobalConfig.commission_detail_export_report_file_name;
        order_export_file_path = order_export_file_path.replaceAll(".xlsx", "_" + sdf_month.format(month_start_date) + ".xlsx");
        try
        {
            FileOutputStream order_output = new FileOutputStream(new File(order_export_file_path));
            // 内存中保留 100条数据，以免内存溢出，其余写入硬盘
            SXSSFWorkbook order_wb = new SXSSFWorkbook(100);
            Sheet order_sheet = order_wb.createSheet("Sheet 1");

            Row order_row = order_sheet.createRow(0);

            CellStyle style_title = order_wb.createCellStyle();
            style_title.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.index);
            style_title.setFillPattern(CellStyle.SOLID_FOREGROUND);
            style_title.setBorderBottom(CellStyle.BORDER_THIN); // 下边框
            style_title.setBorderLeft(CellStyle.BORDER_THIN);// 左边框
            style_title.setBorderTop(CellStyle.BORDER_THIN);// 上边框
            style_title.setBorderRight(CellStyle.BORDER_THIN);// 右边框
            style_title.setAlignment(CellStyle.ALIGN_CENTER);// 居中

            CellStyle style_content = order_wb.createCellStyle();
            style_content.setBorderBottom(CellStyle.BORDER_THIN); // 下边框
            style_content.setBorderLeft(CellStyle.BORDER_THIN);// 左边框
            style_content.setBorderTop(CellStyle.BORDER_THIN);// 上边框
            style_content.setBorderRight(CellStyle.BORDER_THIN);// 右边框

            CellStyle style_content_highlight = order_wb.createCellStyle();
            style_content_highlight.setFillForegroundColor(IndexedColors.YELLOW.index);
            style_content_highlight.setFillPattern(CellStyle.SOLID_FOREGROUND);
            style_content_highlight.setBorderBottom(CellStyle.BORDER_THIN); // 下边框
            style_content_highlight.setBorderLeft(CellStyle.BORDER_THIN);// 左边框
            style_content_highlight.setBorderTop(CellStyle.BORDER_THIN);// 上边框
            style_content_highlight.setBorderRight(CellStyle.BORDER_THIN);// 右边框

            CellStyle style_content_light = order_wb.createCellStyle();
            style_content_light.setBorderBottom(CellStyle.BORDER_THIN); // 下边框
            style_content_light.setBorderLeft(CellStyle.BORDER_THIN);// 左边框
            style_content_light.setBorderTop(CellStyle.BORDER_THIN);// 上边框
            style_content_light.setBorderRight(CellStyle.BORDER_THIN);// 右边框
            Font font_light = order_wb.createFont();
            font_light.setFontName("宋体");
            font_light.setColor(IndexedColors.GREY_40_PERCENT.index);
            style_content_light.setFont(font_light);// 设置字体颜色

            // 报告日期
            Cell cell = order_row.createCell(0);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("报告周次");
            cell.setCellStyle(style_title);
            // 订单编号
            cell = order_row.createCell(1);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("订单编号");
            cell.setCellStyle(style_title);
            // 订单创建时间
            cell = order_row.createCell(2);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("订单创建时间");
            cell.setCellStyle(style_title);
            // 订单完成时间
            cell = order_row.createCell(3);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("订单完成时间");
            cell.setCellStyle(style_title);
            // 付款总额
            cell = order_row.createCell(4);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("付款总额");
            cell.setCellStyle(style_title);
            // 订单状态
            cell = order_row.createCell(5);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("订单状态");
            cell.setCellStyle(style_title);
            // 买家编号
            cell = order_row.createCell(6);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("买家编号");
            cell.setCellStyle(style_content_highlight);
            // 买家昵称
            cell = order_row.createCell(7);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("买家昵称");
            cell.setCellStyle(style_content_highlight);
            // 真实姓名
            cell = order_row.createCell(8);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("真实姓名");
            cell.setCellStyle(style_content_highlight);
            // 身份证号
            cell = order_row.createCell(9);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("身份证号");
            cell.setCellStyle(style_content_highlight);
            // 推荐人编号
            cell = order_row.createCell(10);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("推荐人编号");
            cell.setCellStyle(style_title);
            // 推荐人昵称
            cell = order_row.createCell(11);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("推荐人昵称");
            cell.setCellStyle(style_title);
            // 推荐人所得佣金金额
            cell = order_row.createCell(12);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("推荐人所得佣金金额");
            cell.setCellStyle(style_title);

            int the_whole_order_countInDB = orderDAO.getTotalCountCompleteOrderByBeginTimeAndEndTime(month_start_date, month_end_date);
            int one_page_size_of_whole_order = 100;

            // 设置row_index
            int row_index = 1;
            if (the_whole_order_countInDB > 0)
            {
                int ttpTemp = the_whole_order_countInDB % one_page_size_of_whole_order == 0 ? the_whole_order_countInDB / one_page_size_of_whole_order : the_whole_order_countInDB / one_page_size_of_whole_order + 1;
                for (int i = 1; i <= ttpTemp; i++)
                {
                    List<Order> orderList = orderDAO.getListCompleteOrderByIndexAndPageSizeAndBeginTimeAndEndTime(i, one_page_size_of_whole_order, month_start_date, month_end_date);
                    if (orderList != null && orderList.size() > 0)
                    {
                        for (int j = 0; j < orderList.size(); j++)
                        {
                            Order temp_order = orderList.get(j);

                            // 得到买家信息
                            Buyer buyerFromDB = buyerDAO.findById(temp_order.getBuyerId());
                            if (buyerFromDB == null || buyerFromDB.getBuyerIntroducer() == null)
                            {
                                continue;
                            }

                            // 得到买家推荐人信息
                            Buyer buyerIntroducer = buyerDAO.findById(buyerFromDB.getBuyerIntroducer());
                            if (buyerIntroducer == null)
                            {
                                continue;
                            }

                            int order_row_index = row_index;
                            order_row = order_sheet.createRow(row_index);
                            row_index++;

                            // 报告周次
                            cell = order_row.createCell(0);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(CM.getWeekStringByDate(temp_order.getOrderCompleteTime()));
                            cell.setCellStyle(CM.validWeekHighlight(temp_order.getOrderCompleteTime()) ? style_content_highlight : style_content);
                            // 订单编号
                            cell = order_row.createCell(1);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_order.getOrderId());
                            cell.setCellStyle(style_content);
                            // 订单创建时间
                            cell = order_row.createCell(2);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(sdf.format(temp_order.getOrderBuyTime()));
                            cell.setCellStyle(style_content);
                            // 订单完成时间
                            cell = order_row.createCell(3);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(sdf.format(temp_order.getOrderCompleteTime()));
                            cell.setCellStyle(style_content);
                            // 付款总额
                            cell = order_row.createCell(4);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(String.valueOf(temp_order.getOrderTotalPrice()));
                            cell.setCellStyle(style_content);
                            // 订单状态
                            cell = order_row.createCell(5);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(temp_order.getOrderStatus());
                            cell.setCellStyle(style_content);

                            // 买家编号
                            cell = order_row.createCell(6);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(buyerFromDB.getBuyerId());
                            cell.setCellStyle(style_content);
                            // 买家昵称
                            cell = order_row.createCell(7);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(buyerFromDB.getBuyerNickname() == null ? "" : buyerFromDB.getBuyerNickname());
                            cell.setCellStyle(style_content);
                            // 真实姓名
                            cell = order_row.createCell(8);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(buyerFromDB.getBuyerRealName() == null ? "" : buyerFromDB.getBuyerRealName());
                            cell.setCellStyle(style_content);
                            // 身份证号
                            cell = order_row.createCell(9);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(buyerFromDB.getBuyerPeopleId() == null ? "" : buyerFromDB.getBuyerPeopleId());
                            cell.setCellStyle(style_content);
                            // 推荐人编号
                            cell = order_row.createCell(10);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(buyerIntroducer.getBuyerId());
                            cell.setCellStyle(style_content);
                            // 推荐人昵称
                            cell = order_row.createCell(11);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(buyerIntroducer.getBuyerNickname() == null ? "" : buyerIntroducer.getBuyerNickname());
                            cell.setCellStyle(style_content);
                            // 推荐人所得佣金
                            cell = order_row.createCell(12);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(String.valueOf(0));
                            cell.setCellStyle(style_content);

                            List<OrderGoods> orderGoodList = orderGoodsDAO.findByOrderId(temp_order.getOrderId());
                            if (orderGoodList == null || orderGoodList.size() == 0)
                            {
                                continue;
                            }

                            int goods_index = 1;
                            BigDecimal order_commission = new BigDecimal(0);
                            for (OrderGoods ogTemp : orderGoodList)
                            {
                                Goods goodsFromDB = goodsDAO.findById(ogTemp.getGoodsId());
                                if (goodsFromDB == null)
                                {
                                    continue;
                                }

                                order_row = order_sheet.createRow(row_index);
                                row_index++;
                                // 首列
                                cell = order_row.createCell(0);
                                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                cell.setCellValue("");
                                cell.setCellStyle(CM.validWeekHighlight(temp_order.getOrderCompleteTime()) ? style_content_highlight : style_content);
                                // 订单包含商品
                                cell = order_row.createCell(1);
                                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                cell.setCellValue("订单包含商品" + goods_index);
                                goods_index++;
                                cell.setCellStyle(style_content_light);
                                // 商品编号
                                cell = order_row.createCell(2);
                                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                cell.setCellValue(goodsFromDB.getGoodsId() + "(商品编号)");
                                cell.setCellStyle(style_content_light);
                                // 商品名称
                                cell = order_row.createCell(3);
                                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                cell.setCellValue(goodsFromDB.getGoodsName() + "(商品名称)");
                                cell.setCellStyle(style_content_light);
                                // 商品单价
                                cell = order_row.createCell(4);
                                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                cell.setCellValue(goodsFromDB.getGoodsPrice() + "(商品单价)");
                                cell.setCellStyle(style_content_light);
                                // 商品数量
                                cell = order_row.createCell(5);
                                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                cell.setCellValue(ogTemp.getGoodsNumber() + "(商品数量)");
                                cell.setCellStyle(style_content_light);
                                // 商品普通佣金
                                cell = order_row.createCell(6);
                                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                cell.setCellValue(ogTemp.getGoodsNumber() * goodsFromDB.getGoodsCommission() + "(商品普通佣金)");
                                cell.setCellStyle(style_content_light);
                                GoodsCommission specialCommission = goodsCommissionDAO.findByGoodsIdAndBuyerId(goodsFromDB.getGoodsId(), buyerIntroducer.getBuyerId());
                                if (specialCommission != null)
                                {
                                    // 推荐人对此商品特殊佣金
                                    cell = order_row.createCell(7);
                                    cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                    cell.setCellValue(ogTemp.getGoodsNumber() * specialCommission.getGoodsCommission() + "(推荐人对此商品特殊佣金)");
                                    cell.setCellStyle(style_content_light);

                                    cell = order_row.createCell(8);
                                    cell.setCellStyle(style_content_light);
                                    cell = order_row.createCell(9);
                                    cell.setCellStyle(style_content_light);
                                    cell = order_row.createCell(10);
                                    cell.setCellStyle(style_content_light);
                                    cell = order_row.createCell(11);
                                    cell.setCellStyle(style_content_light);

                                    // 推荐人从此商品获得佣金
                                    cell = order_row.createCell(12);
                                    cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                    cell.setCellValue(ogTemp.getGoodsNumber() * specialCommission.getGoodsCommission() + "(推荐人从此商品获得佣金)");
                                    cell.setCellStyle(style_content_light);

                                    order_commission = order_commission.add(new BigDecimal(ogTemp.getGoodsNumber() * specialCommission.getGoodsCommission()));
                                }
                                else
                                {
                                    cell = order_row.createCell(7);
                                    cell.setCellStyle(style_content_light);
                                    cell = order_row.createCell(8);
                                    cell.setCellStyle(style_content_light);
                                    cell = order_row.createCell(9);
                                    cell.setCellStyle(style_content_light);
                                    cell = order_row.createCell(10);
                                    cell.setCellStyle(style_content_light);
                                    cell = order_row.createCell(11);
                                    cell.setCellStyle(style_content_light);

                                    // 推荐人从此商品获得佣金
                                    cell = order_row.createCell(12);
                                    cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                    cell.setCellValue(ogTemp.getGoodsNumber() * goodsFromDB.getGoodsCommission() + "(推荐人从此商品获得佣金)");
                                    cell.setCellStyle(style_content_light);
                                    order_commission = order_commission.add(new BigDecimal(ogTemp.getGoodsNumber() * goodsFromDB.getGoodsCommission()));
                                }
                            }
                            order_sheet.getRow(order_row_index).getCell(12).setCellType(XSSFCell.CELL_TYPE_STRING);
                            order_sheet.getRow(order_row_index).getCell(12).setCellValue(String.valueOf(order_commission.doubleValue()));
                        }
                    }
                }
            }
            order_wb.write(order_output);
            order_output.close();
        } catch (IOException e)
        {
            e.printStackTrace();
        }

        System.out.println("生成每周佣金明细报表Excel--结束");
    }

    private void batch_export_goods_sales_summary_report_file()
    {
        System.out.println("生成商品销售月汇总报表Excel--开始");

        Date[] dateArray = CM.getMonthReportStartDateAndEndDate(Calendar.getInstance().getTime());
        Date month_start_date = dateArray[0];
        Date month_end_date = dateArray[1];
        // 生成商品销售月汇总报表Excel
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String goods_sales_summary_export_file_path = GlobalConfig.web_server_root_path + "file/report/" + GlobalConfig.goods_sales_summary_report_file_name;
        goods_sales_summary_export_file_path = goods_sales_summary_export_file_path.replaceAll(".xlsx", "_" + sdf_month.format(month_start_date) + ".xlsx");
        try
        {
            FileOutputStream summary_output = new FileOutputStream(new File(goods_sales_summary_export_file_path));
            // 内存中保留 100条数据，以免内存溢出，其余写入硬盘
            SXSSFWorkbook summary_wb = new SXSSFWorkbook(100);
            Sheet summary_sheet = summary_wb.createSheet("Sheet 1");

            Row summary_row = summary_sheet.createRow(0);

            CellStyle style_title = summary_wb.createCellStyle();
            style_title.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.index);
            style_title.setFillPattern(CellStyle.SOLID_FOREGROUND);
            style_title.setBorderBottom(CellStyle.BORDER_THIN); // 下边框
            style_title.setBorderLeft(CellStyle.BORDER_THIN);// 左边框
            style_title.setBorderTop(CellStyle.BORDER_THIN);// 上边框
            style_title.setBorderRight(CellStyle.BORDER_THIN);// 右边框
            style_title.setAlignment(CellStyle.ALIGN_CENTER);// 居中

            CellStyle style_content = summary_wb.createCellStyle();
            style_content.setBorderBottom(CellStyle.BORDER_THIN); // 下边框
            style_content.setBorderLeft(CellStyle.BORDER_THIN);// 左边框
            style_content.setBorderTop(CellStyle.BORDER_THIN);// 上边框
            style_content.setBorderRight(CellStyle.BORDER_THIN);// 右边框

            CellStyle style_content_highlight = summary_wb.createCellStyle();
            style_content_highlight.setFillForegroundColor(IndexedColors.YELLOW.index);
            style_content_highlight.setFillPattern(CellStyle.SOLID_FOREGROUND);
            style_content_highlight.setBorderBottom(CellStyle.BORDER_THIN); // 下边框
            style_content_highlight.setBorderLeft(CellStyle.BORDER_THIN);// 左边框
            style_content_highlight.setBorderTop(CellStyle.BORDER_THIN);// 上边框
            style_content_highlight.setBorderRight(CellStyle.BORDER_THIN);// 右边框

            CellStyle style_content_light = summary_wb.createCellStyle();
            style_content_light.setBorderBottom(CellStyle.BORDER_THIN); // 下边框
            style_content_light.setBorderLeft(CellStyle.BORDER_THIN);// 左边框
            style_content_light.setBorderTop(CellStyle.BORDER_THIN);// 上边框
            style_content_light.setBorderRight(CellStyle.BORDER_THIN);// 右边框
            Font font_light = summary_wb.createFont();
            font_light.setFontName("宋体");
            font_light.setColor(IndexedColors.GREY_40_PERCENT.index);
            style_content_light.setFont(font_light);// 设置字体颜色

            // 商品类型
            Cell cell = summary_row.createCell(0);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("商品类型");
            cell.setCellStyle(style_title);
            // 商品编号
            cell = summary_row.createCell(1);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("商品编号");
            cell.setCellStyle(style_title);
            // 商品名称
            cell = summary_row.createCell(2);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("商品名称");
            cell.setCellStyle(style_title);
            // 月销售数量
            cell = summary_row.createCell(3);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("月销售数量");
            cell.setCellStyle(style_title);
            // 月销售额
            cell = summary_row.createCell(4);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("月销售额");
            cell.setCellStyle(style_title);

            // 设置row_index
            int row_index = 1;

            List<GoodsType> goodsTypeListTemp = goodsTypeDAO.findAll();
            if (goodsTypeListTemp != null && goodsTypeListTemp.size() > 0)
            {

                Map<String, GoodsTypeView> goodsTypeMap = new LinkedHashMap<String, GoodsTypeView>();
                for (GoodsType gt : goodsTypeListTemp)
                {
                    GoodsTypeView gtvTemp = new GoodsTypeView();
                    gtvTemp.setId(gt.getGoodsTypeId());
                    gtvTemp.setName(gt.getGoodsTypeName());
                    gtvTemp.setpId(gt.getGoodsTypeParentId() == null ? "" : gt.getGoodsTypeParentId());
                    gtvTemp.setOpen(true);
                    gtvTemp.setNoR(false);
                    gtvTemp.setPicture(gt.getGoodsTypePic());
                    gtvTemp.setGrade(1);
                    goodsTypeMap.put(gt.getGoodsTypeId(), gtvTemp);
                }
                List<GoodsTypeView> goodsTypeViewListForJson = new ArrayList<GoodsTypeView>();
                Set<Map.Entry<String, GoodsTypeView>> set = goodsTypeMap.entrySet();
                for (Iterator<Map.Entry<String, GoodsTypeView>> it = set.iterator(); it.hasNext(); )
                {
                    Map.Entry<String, GoodsTypeView> entry = (Map.Entry<String, GoodsTypeView>) it.next();
                    if (CM.validIsEmpty(entry.getValue().getpId()))
                    {
                        entry.getValue().setGrade(1);
                        goodsTypeMap.put(entry.getKey(), entry.getValue());
                    }
                    else if (CM.validIsEmpty(goodsTypeMap.get(entry.getValue().getpId()).getpId()))
                    {
                        entry.getValue().setGrade(2);
                        goodsTypeMap.put(entry.getKey(), entry.getValue());
                    }
                    else if (CM.validIsEmpty(goodsTypeMap.get(goodsTypeMap.get(entry.getValue().getpId()).getpId()).getpId()))
                    {
                        entry.getValue().setGrade(3);
                        goodsTypeMap.put(entry.getKey(), entry.getValue());
                    }
                    goodsTypeViewListForJson.add(entry.getValue());
                }

                List<GoodsTypeViewAndList> goodsTypeViewAndListForShowList = new ArrayList<GoodsTypeViewAndList>();
                for (int i = 0; i < goodsTypeViewListForJson.size(); i++)
                {
                    if (goodsTypeViewListForJson.get(i).getGrade() == 1)
                    {
                        GoodsTypeViewAndList goodsTypeViewAndListTemp = new GoodsTypeViewAndList();
                        goodsTypeViewAndListTemp.setView(goodsTypeViewListForJson.get(i));
                        goodsTypeViewAndListForShowList.add(goodsTypeViewAndListTemp);
                    }
                }
                for (int i = 0; i < goodsTypeViewAndListForShowList.size(); i++)
                {
                    List<GoodsTypeViewAndList> goodsTypeViewAndListForShowList_2 = new ArrayList<GoodsTypeViewAndList>();
                    for (int j = 0; j < goodsTypeViewListForJson.size(); j++)
                    {
                        if (goodsTypeViewListForJson.get(j).getGrade() == 2 && goodsTypeViewListForJson.get(j).getpId().equals(goodsTypeViewAndListForShowList.get(i).getView().getId()))
                        {
                            GoodsTypeViewAndList goodsTypeViewAndListTemp = new GoodsTypeViewAndList();
                            goodsTypeViewAndListTemp.setView(goodsTypeViewListForJson.get(j));
                            goodsTypeViewAndListForShowList_2.add(goodsTypeViewAndListTemp);
                        }
                    }
                    goodsTypeViewAndListForShowList.get(i).setList(goodsTypeViewAndListForShowList_2);
                }
                for (int i = 0; i < goodsTypeViewAndListForShowList.size(); i++)
                {
                    String i_Str = "";
                    for (int j = 0; j < goodsTypeViewAndListForShowList.get(i).getList().size(); j++)
                    {
                        String j_Str = "";
                        List<GoodsTypeViewAndList> goodsTypeViewAndListForShowList_3 = new ArrayList<GoodsTypeViewAndList>();
                        for (int k = 0; k < goodsTypeViewListForJson.size(); k++)
                        {
                            if (goodsTypeViewListForJson.get(k).getGrade() == 3 && goodsTypeViewListForJson.get(k).getpId().equals(goodsTypeViewAndListForShowList.get(i).getList().get(j).getView().getId()))
                            {
                                GoodsTypeViewAndList goodsTypeViewAndListTemp = new GoodsTypeViewAndList();
                                goodsTypeViewAndListTemp.setView(goodsTypeViewListForJson.get(k));
                                goodsTypeViewAndListTemp.getView().setChildrenIds(goodsTypeViewAndListTemp.getView().getId());
                                goodsTypeViewAndListForShowList_3.add(goodsTypeViewAndListTemp);
                                // 记录下一级id
                                j_Str += goodsTypeViewListForJson.get(k).getId() + ",";
                            }
                        }
                        j_Str = goodsTypeViewAndListForShowList.get(i).getList().get(j).getView().getId() + "," + j_Str;
                        if (j_Str.length() > 0)
                        {
                            i_Str += j_Str;
                        }
                        // 设置此级别孩子id
                        goodsTypeViewAndListForShowList.get(i).getList().get(j).getView().setChildrenIds(j_Str.length() > 0 ? j_Str.substring(0, j_Str.length() - 1) : "");
                        goodsTypeViewAndListForShowList.get(i).getList().get(j).setList(goodsTypeViewAndListForShowList_3);
                    }
                    i_Str = goodsTypeViewAndListForShowList.get(i).getView().getId() + "," + i_Str;
                    // 设置此级别孩子id
                    goodsTypeViewAndListForShowList.get(i).getView().setChildrenIds(i_Str.length() > 0 ? i_Str.substring(0, i_Str.length() - 1) : "");
                }

                int month_total_sales_number = 0;
                BigDecimal month_total_sales_money = new BigDecimal(0);
                for (GoodsTypeViewAndList gtvl : goodsTypeViewAndListForShowList)
                {
                    String goods_type_id = gtvl.getView().getId();
                    String goods_type_name = gtvl.getView().getName();
                    Map<String, Object> infoMap = getGoodsSalesSummaryInfo(goods_type_id, goods_type_name, summary_sheet, summary_row, row_index, cell, style_content, style_content_highlight, month_start_date, month_end_date);

                    row_index = (int) infoMap.get("row_index");
                    month_total_sales_number += (int) infoMap.get("this_type_total_number");
                    month_total_sales_money = month_total_sales_money.add((BigDecimal) infoMap.get("this_type_total_money"));
                    for (GoodsTypeViewAndList gtvl2 : gtvl.getList())
                    {
                        goods_type_id = gtvl2.getView().getId();
                        goods_type_name = gtvl.getView().getName() + "-->" + gtvl2.getView().getName();
                        infoMap = getGoodsSalesSummaryInfo(goods_type_id, goods_type_name, summary_sheet, summary_row, row_index, cell, style_content, style_content_highlight, month_start_date, month_end_date);

                        row_index = (int) infoMap.get("row_index");
                        month_total_sales_number += (int) infoMap.get("this_type_total_number");
                        month_total_sales_money = month_total_sales_money.add((BigDecimal) infoMap.get("this_type_total_money"));
                        for (GoodsTypeViewAndList gtvl3 : gtvl2.getList())
                        {
                            goods_type_id = gtvl3.getView().getId();
                            goods_type_name = gtvl.getView().getName() + "-->" + gtvl2.getView().getName() + "-->" + gtvl3.getView().getName();

                            infoMap = getGoodsSalesSummaryInfo(goods_type_id, goods_type_name, summary_sheet, summary_row, row_index, cell, style_content, style_content_highlight, month_start_date, month_end_date);

                            row_index = (int) infoMap.get("row_index");
                            month_total_sales_number += (int) infoMap.get("this_type_total_number");
                            month_total_sales_money = month_total_sales_money.add((BigDecimal) infoMap.get("this_type_total_money"));
                        }
                    }
                }

                summary_row = summary_sheet.createRow(row_index);
                row_index++;

                cell = summary_row.createCell(0);
                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                cell.setCellValue("");
                cell.setCellStyle(style_content_highlight);
                cell = summary_row.createCell(1);
                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                cell.setCellValue("");
                cell.setCellStyle(style_content_highlight);
                // 此类型合计
                cell = summary_row.createCell(2);
                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                cell.setCellValue("月总销售合计");
                cell.setCellStyle(style_content_highlight);

                // 月销售数量
                cell = summary_row.createCell(3);
                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                cell.setCellValue(String.valueOf(month_total_sales_number));
                cell.setCellStyle(style_content_highlight);
                // 月销售额
                cell = summary_row.createCell(4);
                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                cell.setCellValue(String.valueOf(month_total_sales_money.doubleValue() > 0 ? month_total_sales_money.doubleValue() : "0"));
                cell.setCellStyle(style_content_highlight);

            }
            summary_wb.write(summary_output);
            summary_output.close();
        } catch (IOException e)
        {
            e.printStackTrace();
        }

        System.out.println("生成商品销售月汇总报表Excel--结束");
    }

    private void batch_export_commission_summary_report_file()
    {
        System.out.println("生成佣金月汇总报表Excel--开始");

        Date[] dateArray = CM.getMonthReportStartDateAndEndDate(Calendar.getInstance().getTime());
        Date month_start_date = dateArray[0];
        Date month_end_date = dateArray[1];
        // 生成佣金月汇总报表Excel
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String commission_summary_export_file_path = GlobalConfig.web_server_root_path + "file/report/" + GlobalConfig.commission_summary_report_file_name;
        commission_summary_export_file_path = commission_summary_export_file_path.replaceAll(".xlsx", "_" + sdf_month.format(month_start_date) + ".xlsx");
        try
        {
            FileOutputStream summary_output = new FileOutputStream(new File(commission_summary_export_file_path));
            // 内存中保留 100条数据，以免内存溢出，其余写入硬盘
            SXSSFWorkbook summary_wb = new SXSSFWorkbook(100);
            Sheet summary_sheet = summary_wb.createSheet("Sheet 1");

            Row summary_row = summary_sheet.createRow(0);

            CellStyle style_title = summary_wb.createCellStyle();
            style_title.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.index);
            style_title.setFillPattern(CellStyle.SOLID_FOREGROUND);
            style_title.setBorderBottom(CellStyle.BORDER_THIN); // 下边框
            style_title.setBorderLeft(CellStyle.BORDER_THIN);// 左边框
            style_title.setBorderTop(CellStyle.BORDER_THIN);// 上边框
            style_title.setBorderRight(CellStyle.BORDER_THIN);// 右边框
            style_title.setAlignment(CellStyle.ALIGN_CENTER);// 居中

            CellStyle style_content = summary_wb.createCellStyle();
            style_content.setBorderBottom(CellStyle.BORDER_THIN); // 下边框
            style_content.setBorderLeft(CellStyle.BORDER_THIN);// 左边框
            style_content.setBorderTop(CellStyle.BORDER_THIN);// 上边框
            style_content.setBorderRight(CellStyle.BORDER_THIN);// 右边框

            CellStyle style_content_highlight = summary_wb.createCellStyle();
            style_content_highlight.setFillForegroundColor(IndexedColors.YELLOW.index);
            style_content_highlight.setFillPattern(CellStyle.SOLID_FOREGROUND);
            style_content_highlight.setBorderBottom(CellStyle.BORDER_THIN); // 下边框
            style_content_highlight.setBorderLeft(CellStyle.BORDER_THIN);// 左边框
            style_content_highlight.setBorderTop(CellStyle.BORDER_THIN);// 上边框
            style_content_highlight.setBorderRight(CellStyle.BORDER_THIN);// 右边框

            CellStyle style_content_light = summary_wb.createCellStyle();
            style_content_light.setBorderBottom(CellStyle.BORDER_THIN); // 下边框
            style_content_light.setBorderLeft(CellStyle.BORDER_THIN);// 左边框
            style_content_light.setBorderTop(CellStyle.BORDER_THIN);// 上边框
            style_content_light.setBorderRight(CellStyle.BORDER_THIN);// 右边框
            Font font_light = summary_wb.createFont();
            font_light.setFontName("宋体");
            font_light.setColor(IndexedColors.GREY_40_PERCENT.index);
            style_content_light.setFont(font_light);// 设置字体颜色

            // 买家类型
            Cell cell = summary_row.createCell(0);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("买家类型");
            cell.setCellStyle(style_title);
            // 买家编号
            cell = summary_row.createCell(1);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("买家编号");
            cell.setCellStyle(style_title);
            // 买家名称(微信昵称)
            cell = summary_row.createCell(2);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("买家名称(微信昵称)");
            cell.setCellStyle(style_title);
            // 商品类型
            cell = summary_row.createCell(3);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("商品类型");
            cell.setCellStyle(style_title);
            // 商品编号
            cell = summary_row.createCell(4);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("商品编号");
            cell.setCellStyle(style_title);
            // 商品名称
            cell = summary_row.createCell(5);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("商品名称");
            cell.setCellStyle(style_title);
            // 下线月度销售数量
            cell = summary_row.createCell(6);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("下线月度销售数量");
            cell.setCellStyle(style_title);
            // 个人佣金汇总金额
            cell = summary_row.createCell(7);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("个人佣金汇总金额");
            cell.setCellStyle(style_title);

            // 设置row_index
            int row_index = 1;

            List<GoodsType> goodsTypeListTemp = goodsTypeDAO.findAll();
            if (goodsTypeListTemp != null && goodsTypeListTemp.size() > 0)
            {

                Map<String, GoodsTypeView> goodsTypeMap = new LinkedHashMap<String, GoodsTypeView>();
                for (GoodsType gt : goodsTypeListTemp)
                {
                    GoodsTypeView gtvTemp = new GoodsTypeView();
                    gtvTemp.setId(gt.getGoodsTypeId());
                    gtvTemp.setName(gt.getGoodsTypeName());
                    gtvTemp.setpId(gt.getGoodsTypeParentId() == null ? "" : gt.getGoodsTypeParentId());
                    gtvTemp.setOpen(true);
                    gtvTemp.setNoR(false);
                    gtvTemp.setPicture(gt.getGoodsTypePic());
                    gtvTemp.setGrade(1);
                    goodsTypeMap.put(gt.getGoodsTypeId(), gtvTemp);
                }
                List<GoodsTypeView> goodsTypeViewListForJson = new ArrayList<GoodsTypeView>();
                Set<Map.Entry<String, GoodsTypeView>> set = goodsTypeMap.entrySet();
                for (Iterator<Map.Entry<String, GoodsTypeView>> it = set.iterator(); it.hasNext(); )
                {
                    Map.Entry<String, GoodsTypeView> entry = (Map.Entry<String, GoodsTypeView>) it.next();
                    if (CM.validIsEmpty(entry.getValue().getpId()))
                    {
                        entry.getValue().setGrade(1);
                        goodsTypeMap.put(entry.getKey(), entry.getValue());
                    }
                    else if (CM.validIsEmpty(goodsTypeMap.get(entry.getValue().getpId()).getpId()))
                    {
                        entry.getValue().setGrade(2);
                        goodsTypeMap.put(entry.getKey(), entry.getValue());
                    }
                    else if (CM.validIsEmpty(goodsTypeMap.get(goodsTypeMap.get(entry.getValue().getpId()).getpId()).getpId()))
                    {
                        entry.getValue().setGrade(3);
                        goodsTypeMap.put(entry.getKey(), entry.getValue());
                    }
                    goodsTypeViewListForJson.add(entry.getValue());
                }

                List<GoodsTypeViewAndList> goodsTypeViewAndListForShowList = new ArrayList<GoodsTypeViewAndList>();
                for (int i = 0; i < goodsTypeViewListForJson.size(); i++)
                {
                    if (goodsTypeViewListForJson.get(i).getGrade() == 1)
                    {
                        GoodsTypeViewAndList goodsTypeViewAndListTemp = new GoodsTypeViewAndList();
                        goodsTypeViewAndListTemp.setView(goodsTypeViewListForJson.get(i));
                        goodsTypeViewAndListForShowList.add(goodsTypeViewAndListTemp);
                    }
                }
                for (int i = 0; i < goodsTypeViewAndListForShowList.size(); i++)
                {
                    List<GoodsTypeViewAndList> goodsTypeViewAndListForShowList_2 = new ArrayList<GoodsTypeViewAndList>();
                    for (int j = 0; j < goodsTypeViewListForJson.size(); j++)
                    {
                        if (goodsTypeViewListForJson.get(j).getGrade() == 2 && goodsTypeViewListForJson.get(j).getpId().equals(goodsTypeViewAndListForShowList.get(i).getView().getId()))
                        {
                            GoodsTypeViewAndList goodsTypeViewAndListTemp = new GoodsTypeViewAndList();
                            goodsTypeViewAndListTemp.setView(goodsTypeViewListForJson.get(j));
                            goodsTypeViewAndListForShowList_2.add(goodsTypeViewAndListTemp);
                        }
                    }
                    goodsTypeViewAndListForShowList.get(i).setList(goodsTypeViewAndListForShowList_2);
                }
                for (int i = 0; i < goodsTypeViewAndListForShowList.size(); i++)
                {
                    String i_Str = "";
                    for (int j = 0; j < goodsTypeViewAndListForShowList.get(i).getList().size(); j++)
                    {
                        String j_Str = "";
                        List<GoodsTypeViewAndList> goodsTypeViewAndListForShowList_3 = new ArrayList<GoodsTypeViewAndList>();
                        for (int k = 0; k < goodsTypeViewListForJson.size(); k++)
                        {
                            if (goodsTypeViewListForJson.get(k).getGrade() == 3 && goodsTypeViewListForJson.get(k).getpId().equals(goodsTypeViewAndListForShowList.get(i).getList().get(j).getView().getId()))
                            {
                                GoodsTypeViewAndList goodsTypeViewAndListTemp = new GoodsTypeViewAndList();
                                goodsTypeViewAndListTemp.setView(goodsTypeViewListForJson.get(k));
                                goodsTypeViewAndListTemp.getView().setChildrenIds(goodsTypeViewAndListTemp.getView().getId());
                                goodsTypeViewAndListForShowList_3.add(goodsTypeViewAndListTemp);
                                // 记录下一级id
                                j_Str += goodsTypeViewListForJson.get(k).getId() + ",";
                            }
                        }
                        j_Str = goodsTypeViewAndListForShowList.get(i).getList().get(j).getView().getId() + "," + j_Str;
                        if (j_Str.length() > 0)
                        {
                            i_Str += j_Str;
                        }
                        // 设置此级别孩子id
                        goodsTypeViewAndListForShowList.get(i).getList().get(j).getView().setChildrenIds(j_Str.length() > 0 ? j_Str.substring(0, j_Str.length() - 1) : "");
                        goodsTypeViewAndListForShowList.get(i).getList().get(j).setList(goodsTypeViewAndListForShowList_3);
                    }
                    i_Str = goodsTypeViewAndListForShowList.get(i).getView().getId() + "," + i_Str;
                    // 设置此级别孩子id
                    goodsTypeViewAndListForShowList.get(i).getView().setChildrenIds(i_Str.length() > 0 ? i_Str.substring(0, i_Str.length() - 1) : "");
                }

                List<String> typeList = new ArrayList<String>();
                typeList.add(IStatus.BUYER_TYPE_1);
                typeList.add(IStatus.BUYER_TYPE_2);
                typeList.add(IStatus.BUYER_TYPE_3);
                typeList.add(IStatus.BUYER_TYPE_4);
                typeList.add(IStatus.BUYER_TYPE_5);
                typeList.add(IStatus.BUYER_TYPE_6);
                typeList.add(IStatus.BUYER_TYPE_7);
                typeList.add(IStatus.BUYER_TYPE_8);
                typeList.add(IStatus.BUYER_TYPE_9);
                typeList.add(IStatus.BUYER_TYPE_10);
                typeList.add(IStatus.BUYER_TYPE_11);

                // 找到需要计算佣金的人员
                int need_count_buyer_number = buyerDAO.getTotalCountByStatusAndTypeList_keyword(IStatus.BUYER_STATUS_USED, typeList, null);

                if (need_count_buyer_number > 0)
                {
                    int ttpTemp = need_count_buyer_number % onePageSize_2 == 0 ? need_count_buyer_number / onePageSize_2 : need_count_buyer_number / onePageSize_2 + 1;
                    for (int i = 1; i <= ttpTemp; i++)
                    {
                        List<Buyer> buyerList = buyerDAO.getListByIndexAndPageSizeAndStatusAndTypeList_keyword(i, onePageSize_2, IStatus.BUYER_STATUS_USED, typeList, null);
                        if (buyerList != null && buyerList.size() > 0)
                        {
                            for (Buyer buyerTemp : buyerList)
                            {
                                int month_total_sales_number = 0;
                                BigDecimal month_total_sales_money = new BigDecimal(0);
                                for (GoodsTypeViewAndList gtvl : goodsTypeViewAndListForShowList)
                                {
                                    String goods_type_id = gtvl.getView().getId();
                                    String goods_type_name = gtvl.getView().getName();
                                    Map<String, Object> infoMap = getCommissionSummaryInfo(buyerTemp, goods_type_id, goods_type_name, summary_sheet, summary_row, row_index, cell, style_content, style_content_highlight, month_start_date, month_end_date);

                                    row_index = (int) infoMap.get("row_index");
                                    month_total_sales_number += (int) infoMap.get("this_type_total_number");
                                    month_total_sales_money = month_total_sales_money.add((BigDecimal) infoMap.get("this_type_total_money"));
                                    for (GoodsTypeViewAndList gtvl2 : gtvl.getList())
                                    {
                                        goods_type_id = gtvl2.getView().getId();
                                        goods_type_name = gtvl.getView().getName() + "-->" + gtvl2.getView().getName();
                                        infoMap = getCommissionSummaryInfo(buyerTemp, goods_type_id, goods_type_name, summary_sheet, summary_row, row_index, cell, style_content, style_content_highlight, month_start_date, month_end_date);

                                        row_index = (int) infoMap.get("row_index");
                                        month_total_sales_number += (int) infoMap.get("this_type_total_number");
                                        month_total_sales_money = month_total_sales_money.add((BigDecimal) infoMap.get("this_type_total_money"));
                                        for (GoodsTypeViewAndList gtvl3 : gtvl2.getList())
                                        {
                                            goods_type_id = gtvl3.getView().getId();
                                            goods_type_name = gtvl.getView().getName() + "-->" + gtvl2.getView().getName() + "-->" + gtvl3.getView().getName();

                                            infoMap = getCommissionSummaryInfo(buyerTemp, goods_type_id, goods_type_name, summary_sheet, summary_row, row_index, cell, style_content, style_content_highlight, month_start_date, month_end_date);

                                            row_index = (int) infoMap.get("row_index");
                                            month_total_sales_number += (int) infoMap.get("this_type_total_number");
                                            month_total_sales_money = month_total_sales_money.add((BigDecimal) infoMap.get("this_type_total_money"));
                                        }
                                    }
                                }

                                summary_row = summary_sheet.createRow(row_index);
                                row_index++;

                                cell = summary_row.createCell(0);
                                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                cell.setCellValue("");
                                cell.setCellStyle(style_content_highlight);
                                cell = summary_row.createCell(1);
                                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                cell.setCellValue("");
                                cell.setCellStyle(style_content_highlight);
                                cell = summary_row.createCell(2);
                                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                cell.setCellValue("");
                                cell.setCellStyle(style_content_highlight);
                                cell = summary_row.createCell(3);
                                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                cell.setCellValue("");
                                cell.setCellStyle(style_content_highlight);
                                cell = summary_row.createCell(4);
                                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                cell.setCellValue("");
                                cell.setCellStyle(style_content_highlight);
                                // 此买家月度佣金总额合计
                                cell = summary_row.createCell(5);
                                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                cell.setCellValue("此买家月度佣金总额合计");
                                cell.setCellStyle(style_content_highlight);
                                // 月销售数量
                                cell = summary_row.createCell(6);
                                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                cell.setCellValue(String.valueOf(month_total_sales_number));
                                cell.setCellStyle(style_content_highlight);
                                // 月销售额
                                cell = summary_row.createCell(7);
                                cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                                cell.setCellValue(String.valueOf(month_total_sales_money.doubleValue() > 0 ? month_total_sales_money.doubleValue() : "0"));
                                cell.setCellStyle(style_content_highlight);
                            }
                        }
                    }
                }
            }
            summary_wb.write(summary_output);
            summary_output.close();
        } catch (IOException e)
        {
            e.printStackTrace();
        }

        System.out.println("生成佣金月汇总报表Excel--结束");
    }

    private void batch_count_commission_day_record()
    {
        System.out.println("批量计算每日佣金--开始");

        List<String> typeList = new ArrayList<String>();
        typeList.add(IStatus.BUYER_TYPE_1);
        typeList.add(IStatus.BUYER_TYPE_2);
        typeList.add(IStatus.BUYER_TYPE_3);
        typeList.add(IStatus.BUYER_TYPE_4);
        typeList.add(IStatus.BUYER_TYPE_5);
        typeList.add(IStatus.BUYER_TYPE_6);
        typeList.add(IStatus.BUYER_TYPE_7);
        typeList.add(IStatus.BUYER_TYPE_8);
        typeList.add(IStatus.BUYER_TYPE_9);
        typeList.add(IStatus.BUYER_TYPE_10);
        typeList.add(IStatus.BUYER_TYPE_11);

        // 找到需要计算佣金的人员
        int need_count_buyer_number = buyerDAO.getTotalCountByStatusAndTypeList_keyword(IStatus.BUYER_STATUS_USED, typeList, null);

        // 每日凌晨再次计算前10天的,避免系统宕机错过定时任务
        for (int day = -10; day <= 0; day++)
        {
            Calendar cald = Calendar.getInstance();
            cald.add(Calendar.DAY_OF_MONTH, day);

            // 当天凌晨计算昨天的,所以要减去一天
            cald.add(Calendar.DAY_OF_MONTH, -1);
            cald.set(Calendar.HOUR_OF_DAY, 0);
            cald.set(Calendar.MINUTE, 0);
            cald.set(Calendar.SECOND, 0);
            cald.set(Calendar.MILLISECOND, 0);
            // 开始时间当天0时0分0秒0毫秒
            Date beginTime = cald.getTime();
            cald.set(Calendar.HOUR_OF_DAY, 23);
            cald.set(Calendar.MINUTE, 59);
            cald.set(Calendar.SECOND, 59);
            cald.set(Calendar.MILLISECOND, 999);
            // 结束时间当天23时59分59秒999毫秒
            Date endTime = cald.getTime();

            cald.set(Calendar.DAY_OF_MONTH, 1);
            cald.set(Calendar.HOUR_OF_DAY, 0);
            cald.set(Calendar.MINUTE, 0);
            cald.set(Calendar.SECOND, 0);
            cald.set(Calendar.MILLISECOND, 0);
            // 当月第一天0时0分0秒0毫秒
            Date month_beginTime = cald.getTime();
            // 昨天0时0分0秒0毫秒
            Date month_endTime = beginTime;

            if (need_count_buyer_number > 0)
            {
                int ttpTemp = need_count_buyer_number % onePageSize_2 == 0 ? need_count_buyer_number / onePageSize_2 : need_count_buyer_number / onePageSize_2 + 1;
                for (int i = 1; i <= ttpTemp; i++)
                {
                    List<Buyer> buyerList = buyerDAO.getListByIndexAndPageSizeAndStatusAndTypeList_keyword(i, onePageSize_2, IStatus.BUYER_STATUS_USED, typeList, null);
                    if (buyerList != null && buyerList.size() > 0)
                    {
                        for (Buyer buyerTemp : buyerList)
                        {
                            // 找到此人的所有一级下线买家
                            int buyer_number_of_this_introducer = buyerDAO.getTotalCountByBuyerIntroducer(buyerTemp.getBuyerId());
                            if (buyer_number_of_this_introducer == 0)
                            {
                                CommissionDayRecord dayRecord = new CommissionDayRecord();
                                dayRecord.setRecordId(CM.getRandomTwentyFivePrimaryKeyId());
                                dayRecord.setBuyerId(buyerTemp.getBuyerId());
                                dayRecord.setTotalBuyerNumber(0);
                                dayRecord.setDayOrderNumber(0);
                                dayRecord.setDayGoodsNumber(0);
                                dayRecord.setDayCommission(0.0);
                                dayRecord.setCurrentMonthCommission(0.0);
                                dayRecord.setRecordDate(beginTime);

                                CommissionDayRecord dayRecordFromDB = commissionDayRecordDAO.findByBuyerIdAndRecordDate(buyerTemp.getBuyerId(), beginTime);
                                if (dayRecordFromDB == null)
                                {
                                    commissionDayRecordDAO.save(dayRecord);
                                }
                            }
                            else if (buyer_number_of_this_introducer > 0)
                            {
                                int totalBuyerNumber = buyer_number_of_this_introducer;
                                int dayOrderNumber = 0;
                                int dayGoodsNumber = 0;
                                BigDecimal day_commission = new BigDecimal(0);
                                double currentMonthCommission = 0;

                                int ttpTemp2 = buyer_number_of_this_introducer % onePageSize_5 == 0 ? buyer_number_of_this_introducer / onePageSize_5 : buyer_number_of_this_introducer / onePageSize_5 + 1;
                                for (int j = 1; j <= ttpTemp2; j++)
                                {
                                    List<Buyer> buyerListOfThisIntroducer = buyerDAO.getListByIndexAndPageSizeAndBuyerIntroducer(j, onePageSize_5, buyerTemp.getBuyerId());
                                    for (Buyer bT : buyerListOfThisIntroducer)
                                    {
                                        // 找到下线买家当日已完成的订单
                                        int order_count = orderDAO.getTotalCountCompleteOrderByBuyerIdAndBeginTimeAndEndTime(bT.getBuyerId(), beginTime, endTime);

                                        // 设置当日订单数量
                                        dayOrderNumber += order_count;

                                        int ttpTemp3 = order_count % onePageSize_10 == 0 ? order_count / onePageSize_10 : order_count / onePageSize_10 + 1;
                                        for (int k = 1; k <= ttpTemp3; k++)
                                        {
                                            List<Order> orderList = orderDAO.getListCompleteOrderByBuyerIdAndIndexAndPageSizeAndBeginTimeAndEndTime(bT.getBuyerId(), k, onePageSize_10, beginTime, endTime);
                                            for (Order oT : orderList)
                                            {
                                                List<OrderGoods> orderGoodsList = orderGoodsDAO.findByOrderId(oT.getOrderId());
                                                for (OrderGoods orderGoodsTemp : orderGoodsList)
                                                {
                                                    // 设置当日商品数量
                                                    dayGoodsNumber += orderGoodsTemp.getGoodsNumber();

                                                    // 找到每个订单所包含的商品
                                                    Goods goodsTemp = goodsDAO.findById(orderGoodsTemp.getGoodsId());
                                                    // 查看此商品对此人是否有特殊佣金
                                                    GoodsCommission specialCommission = goodsCommissionDAO.findByGoodsIdAndBuyerId(goodsTemp.getGoodsId(), buyerTemp.getBuyerId());
                                                    if (specialCommission == null)
                                                    {
                                                        if (goodsTemp.getGoodsCommission() != null)
                                                        {
                                                            day_commission = day_commission.add(new BigDecimal(goodsTemp.getGoodsCommission()).multiply(new BigDecimal(orderGoodsTemp.getGoodsNumber())));

                                                            // 存储佣金明细
                                                            CommissionDetailRecord detailRecordFromDB = commissionDetailRecordDAO.findByBuyerIdAndOrderIdAndGoodsId(buyerTemp.getBuyerId(), oT.getOrderId(), goodsTemp.getGoodsId());
                                                            if (detailRecordFromDB == null)
                                                            {
                                                                CommissionDetailRecord detailRecord = new CommissionDetailRecord();
                                                                detailRecord.setRecordId(CM.getRandomTwentyFivePrimaryKeyId());
                                                                detailRecord.setBuyerId(buyerTemp.getBuyerId());
                                                                detailRecord.setOrderId(oT.getOrderId());
                                                                detailRecord.setGoodsId(goodsTemp.getGoodsId());
                                                                detailRecord.setGoodsNumber(orderGoodsTemp.getGoodsNumber());
                                                                detailRecord.setBuyerCommission(new BigDecimal(goodsTemp.getGoodsCommission()).multiply(new BigDecimal(orderGoodsTemp.getGoodsNumber())).doubleValue());
                                                                detailRecord.setRecordTime(new Timestamp(beginTime.getTime()));
                                                                commissionDetailRecordDAO.save(detailRecord);
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        day_commission = day_commission.add(new BigDecimal(specialCommission.getGoodsCommission()).multiply(new BigDecimal(orderGoodsTemp.getGoodsNumber())));

                                                        // 存储佣金明细
                                                        CommissionDetailRecord detailRecordFromDB = commissionDetailRecordDAO.findByBuyerIdAndOrderIdAndGoodsId(buyerTemp.getBuyerId(), oT.getOrderId(), goodsTemp.getGoodsId());
                                                        if (detailRecordFromDB == null)
                                                        {
                                                            CommissionDetailRecord detailRecord = new CommissionDetailRecord();
                                                            detailRecord.setRecordId(CM.getRandomTwentyFivePrimaryKeyId());
                                                            detailRecord.setBuyerId(buyerTemp.getBuyerId());
                                                            detailRecord.setOrderId(oT.getOrderId());
                                                            detailRecord.setGoodsId(goodsTemp.getGoodsId());
                                                            detailRecord.setGoodsNumber(orderGoodsTemp.getGoodsNumber());
                                                            detailRecord.setBuyerCommission(new BigDecimal(specialCommission.getGoodsCommission()).multiply(new BigDecimal(orderGoodsTemp.getGoodsNumber())).doubleValue());
                                                            detailRecord.setRecordTime(new Timestamp(beginTime.getTime()));
                                                            commissionDetailRecordDAO.save(detailRecord);
                                                        }
                                                    }
                                                }
                                            }
                                        }

                                        Map<String, Object> infoMap = getBuyerFirstLevelXiaXianCommissionInfo(bT.getBuyerId(), buyerTemp.getBuyerId(), beginTime, endTime, month_beginTime, month_endTime);
                                        if (infoMap != null)
                                        {
                                            totalBuyerNumber += (int) (infoMap.get("totalBuyerNumber"));
                                            dayOrderNumber += (int) (infoMap.get("dayOrderNumber"));
                                            dayGoodsNumber += (int) (infoMap.get("dayGoodsNumber"));
                                            day_commission = day_commission.add(new BigDecimal((double) (infoMap.get("dayCommission"))));
                                        }
                                    }
                                }

                                currentMonthCommission = commissionDayRecordDAO.getTotalCommissionByBuyerIdAndBeginTimeAndEndTime(buyerTemp.getBuyerId(), month_beginTime, month_endTime);
                                if (currentMonthCommission >= 0)
                                {
                                    currentMonthCommission = day_commission.add(new BigDecimal(currentMonthCommission)).doubleValue();

                                    CommissionDayRecord dayRecord = new CommissionDayRecord();
                                    dayRecord.setRecordId(CM.getRandomTwentyFivePrimaryKeyId());
                                    dayRecord.setBuyerId(buyerTemp.getBuyerId());
                                    dayRecord.setTotalBuyerNumber(totalBuyerNumber);
                                    dayRecord.setDayOrderNumber(dayOrderNumber);
                                    dayRecord.setDayGoodsNumber(dayGoodsNumber);
                                    dayRecord.setDayCommission(day_commission.doubleValue());
                                    dayRecord.setCurrentMonthCommission(currentMonthCommission);
                                    dayRecord.setRecordDate(beginTime);

                                    CommissionDayRecord dayRecordFromDB = commissionDayRecordDAO.findByBuyerIdAndRecordDate(buyerTemp.getBuyerId(), beginTime);
                                    if (dayRecordFromDB == null)
                                    {
                                        commissionDayRecordDAO.save(dayRecord);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        System.out.println("批量计算每日佣金--结束");
    }

    private void batch_count_pre_commission_day_record()
    {
        System.out.println("批量计算预测每日佣金--开始");

        List<String> typeList = new ArrayList<String>();
        typeList.add(IStatus.BUYER_TYPE_1);
        typeList.add(IStatus.BUYER_TYPE_2);
        typeList.add(IStatus.BUYER_TYPE_3);
        typeList.add(IStatus.BUYER_TYPE_4);
        typeList.add(IStatus.BUYER_TYPE_5);
        typeList.add(IStatus.BUYER_TYPE_6);
        typeList.add(IStatus.BUYER_TYPE_7);
        typeList.add(IStatus.BUYER_TYPE_8);
        typeList.add(IStatus.BUYER_TYPE_9);
        typeList.add(IStatus.BUYER_TYPE_10);
        typeList.add(IStatus.BUYER_TYPE_11);

        // 找到需要计算佣金的人员
        int need_count_buyer_number = buyerDAO.getTotalCountByStatusAndTypeList_keyword(IStatus.BUYER_STATUS_USED, typeList, null);

        // 每日凌晨再次计算前10天的,避免系统宕机错过定时任务
        for (int day = -10; day <= 0; day++)
        {
            Calendar cald = Calendar.getInstance();
            cald.add(Calendar.DAY_OF_MONTH, day);

            // 当天凌晨计算昨天的,所以要减去一天
            cald.add(Calendar.DAY_OF_MONTH, -1);
            cald.set(Calendar.HOUR_OF_DAY, 0);
            cald.set(Calendar.MINUTE, 0);
            cald.set(Calendar.SECOND, 0);
            cald.set(Calendar.MILLISECOND, 0);
            // 开始时间当天0时0分0秒0毫秒
            Date beginTime = cald.getTime();
            cald.set(Calendar.HOUR_OF_DAY, 23);
            cald.set(Calendar.MINUTE, 59);
            cald.set(Calendar.SECOND, 59);
            cald.set(Calendar.MILLISECOND, 999);
            // 结束时间当天23时59分59秒999毫秒
            Date endTime = cald.getTime();

            cald.set(Calendar.DAY_OF_MONTH, 1);
            cald.set(Calendar.HOUR_OF_DAY, 0);
            cald.set(Calendar.MINUTE, 0);
            cald.set(Calendar.SECOND, 0);
            cald.set(Calendar.MILLISECOND, 0);
            // 当月第一天0时0分0秒0毫秒
            Date month_beginTime = cald.getTime();
            // 昨天0时0分0秒0毫秒
            Date month_endTime = beginTime;

            if (need_count_buyer_number > 0)
            {
                int ttpTemp = need_count_buyer_number % onePageSize_2 == 0 ? need_count_buyer_number / onePageSize_2 : need_count_buyer_number / onePageSize_2 + 1;
                for (int i = 1; i <= ttpTemp; i++)
                {
                    List<Buyer> buyerList = buyerDAO.getListByIndexAndPageSizeAndStatusAndTypeList_keyword(i, onePageSize_2, IStatus.BUYER_STATUS_USED, typeList, null);
                    if (buyerList != null && buyerList.size() > 0)
                    {
                        for (Buyer buyerTemp : buyerList)
                        {
                            // 找到此人的所有一级下线买家
                            int buyer_number_of_this_introducer = buyerDAO.getTotalCountByBuyerIntroducer(buyerTemp.getBuyerId());
                            if (buyer_number_of_this_introducer == 0)
                            {
                                PreCommissionDayRecord dayRecord = new PreCommissionDayRecord();
                                dayRecord.setRecordId(CM.getRandomTwentyFivePrimaryKeyId());
                                dayRecord.setBuyerId(buyerTemp.getBuyerId());
                                dayRecord.setTotalBuyerNumber(0);
                                dayRecord.setDayOrderNumber(0);
                                dayRecord.setDayGoodsNumber(0);
                                dayRecord.setDayCommission(0.0);
                                dayRecord.setCurrentMonthCommission(0.0);
                                dayRecord.setRecordDate(beginTime);

                                PreCommissionDayRecord dayRecordFromDB = preCommissionDayRecordDAO.findByBuyerIdAndRecordDate(buyerTemp.getBuyerId(), beginTime);
                                if (dayRecordFromDB == null)
                                {
                                    preCommissionDayRecordDAO.save(dayRecord);
                                }
                            }
                            else if (buyer_number_of_this_introducer > 0)
                            {
                                int totalBuyerNumber = buyer_number_of_this_introducer;
                                int dayOrderNumber = 0;
                                int dayGoodsNumber = 0;
                                BigDecimal day_commission = new BigDecimal(0);
                                double currentMonthCommission = 0;

                                int ttpTemp2 = buyer_number_of_this_introducer % onePageSize_5 == 0 ? buyer_number_of_this_introducer / onePageSize_5 : buyer_number_of_this_introducer / onePageSize_5 + 1;
                                for (int j = 1; j <= ttpTemp2; j++)
                                {
                                    List<Buyer> buyerListOfThisIntroducer = buyerDAO.getListByIndexAndPageSizeAndBuyerIntroducer(j, onePageSize_5, buyerTemp.getBuyerId());
                                    for (Buyer bT : buyerListOfThisIntroducer)
                                    {
                                        // 找到下线买家当日已付款的订单
                                        int order_count = orderDAO.getTotalCountPayedOrderByBuyIdAndBeginTimeAndEndTime(bT.getBuyerId(), beginTime, endTime);

                                        // 设置当日订单数量
                                        dayOrderNumber += order_count;

                                        int ttpTemp3 = order_count % onePageSize_10 == 0 ? order_count / onePageSize_10 : order_count / onePageSize_10 + 1;
                                        for (int k = 1; k <= ttpTemp3; k++)
                                        {
                                            List<Order> orderList = orderDAO.getListPayedOrderByBuyerIdAndIndexAndPageSizeAndBeginTimeAndEndTime(bT.getBuyerId(), k, onePageSize_10, beginTime, endTime);
                                            for (Order oT : orderList)
                                            {
                                                List<OrderGoods> orderGoodsList = orderGoodsDAO.findByOrderId(oT.getOrderId());
                                                for (OrderGoods orderGoodsTemp : orderGoodsList)
                                                {
                                                    // 设置当日商品数量
                                                    dayGoodsNumber += orderGoodsTemp.getGoodsNumber();

                                                    // 找到每个订单所包含的商品
                                                    Goods goodsTemp = goodsDAO.findById(orderGoodsTemp.getGoodsId());
                                                    // 查看此商品对此人是否有特殊佣金
                                                    GoodsCommission specialCommission = goodsCommissionDAO.findByGoodsIdAndBuyerId(goodsTemp.getGoodsId(), buyerTemp.getBuyerId());
                                                    if (specialCommission == null)
                                                    {
                                                        if (goodsTemp.getGoodsCommission() != null)
                                                        {
                                                            day_commission = day_commission.add(new BigDecimal(goodsTemp.getGoodsCommission()).multiply(new BigDecimal(orderGoodsTemp.getGoodsNumber())));
                                                        }
                                                    }
                                                    else
                                                    {
                                                        day_commission = day_commission.add(new BigDecimal(specialCommission.getGoodsCommission()).multiply(new BigDecimal(orderGoodsTemp.getGoodsNumber())));
                                                    }
                                                }
                                            }
                                        }

                                        Map<String, Object> infoMap = getBuyerFirstLevelXiaXianPreCommissionInfo(bT.getBuyerId(), buyerTemp.getBuyerId(), beginTime, endTime, month_beginTime, month_endTime);
                                        if (infoMap != null)
                                        {
                                            totalBuyerNumber += (int) (infoMap.get("totalBuyerNumber"));
                                            dayOrderNumber += (int) (infoMap.get("dayOrderNumber"));
                                            dayGoodsNumber += (int) (infoMap.get("dayGoodsNumber"));
                                            day_commission = day_commission.add(new BigDecimal((double) (infoMap.get("dayCommission"))));
                                        }
                                    }
                                }

                                currentMonthCommission = preCommissionDayRecordDAO.getTotalCommissionByBuyerIdAndBeginTimeAndEndTime(buyerTemp.getBuyerId(), month_beginTime, month_endTime);
                                if (currentMonthCommission >= 0)
                                {
                                    currentMonthCommission = day_commission.add(new BigDecimal(currentMonthCommission)).doubleValue();

                                    PreCommissionDayRecord dayRecord = new PreCommissionDayRecord();
                                    dayRecord.setRecordId(CM.getRandomTwentyFivePrimaryKeyId());
                                    dayRecord.setBuyerId(buyerTemp.getBuyerId());
                                    dayRecord.setTotalBuyerNumber(totalBuyerNumber);
                                    dayRecord.setDayOrderNumber(dayOrderNumber);
                                    dayRecord.setDayGoodsNumber(dayGoodsNumber);
                                    dayRecord.setDayCommission(day_commission.doubleValue());
                                    dayRecord.setCurrentMonthCommission(currentMonthCommission);
                                    dayRecord.setRecordDate(beginTime);

                                    PreCommissionDayRecord dayRecordFromDB = preCommissionDayRecordDAO.findByBuyerIdAndRecordDate(buyerTemp.getBuyerId(), beginTime);
                                    if (dayRecordFromDB == null)
                                    {
                                        preCommissionDayRecordDAO.save(dayRecord);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        System.out.println("批量计算预测每日佣金--结束");
    }

    private Map<String, Object> getBuyerFirstLevelXiaXianCommissionInfo(String buyerId, String topBuyerId, Date day_beginTime, Date day_endTime, Date month_beginTime, Date month_endTime)
    {
        int onePageSize_2 = 2;
        int onePageSize_5 = 5;
        int onePageSize_10 = 10;

        Map<String, Object> infoMap = new HashMap<String, Object>();

        // 找到此人的所有一级下线买家
        int buyer_number_of_this_introducer = buyerDAO.getTotalCountByBuyerIntroducer(buyerId);
        if (buyer_number_of_this_introducer == 0)
        {
            infoMap.put("totalBuyerNumber", 0);
            infoMap.put("dayOrderNumber", 0);
            infoMap.put("dayGoodsNumber", 0);
            infoMap.put("dayCommission", 0.0);
            infoMap.put("currentMonthCommission", 0.0);

            return infoMap;
        }
        else if (buyer_number_of_this_introducer > 0)
        {
            int totalBuyerNumber = buyer_number_of_this_introducer;
            int dayOrderNumber = 0;
            int dayGoodsNumber = 0;
            BigDecimal day_commission = new BigDecimal(0);
            double currentMonthCommission = 0;

            int ttpTemp2 = buyer_number_of_this_introducer % onePageSize_5 == 0 ? buyer_number_of_this_introducer / onePageSize_5 : buyer_number_of_this_introducer / onePageSize_5 + 1;
            for (int j = 1; j <= ttpTemp2; j++)
            {
                List<Buyer> buyerListOfThisIntroducer = buyerDAO.getListByIndexAndPageSizeAndBuyerIntroducer(j, onePageSize_5, buyerId);
                for (Buyer bT : buyerListOfThisIntroducer)
                {
                    // 找到下线买家当日已完成的订单
                    int order_count = orderDAO.getTotalCountCompleteOrderByBuyerIdAndBeginTimeAndEndTime(bT.getBuyerId(), day_beginTime, day_endTime);

                    // 设置当日订单数量
                    dayOrderNumber += order_count;

                    int ttpTemp3 = order_count % onePageSize_10 == 0 ? order_count / onePageSize_10 : order_count / onePageSize_10 + 1;
                    for (int k = 1; k <= ttpTemp3; k++)
                    {
                        List<Order> orderList = orderDAO.getListCompleteOrderByBuyerIdAndIndexAndPageSizeAndBeginTimeAndEndTime(bT.getBuyerId(), k, onePageSize_10, day_beginTime, day_endTime);
                        for (Order oT : orderList)
                        {
                            List<OrderGoods> orderGoodsList = orderGoodsDAO.findByOrderId(oT.getOrderId());
                            for (OrderGoods orderGoodsTemp : orderGoodsList)
                            {
                                // 设置当日商品数量
                                dayGoodsNumber += orderGoodsTemp.getGoodsNumber();

                                // 找到每个订单所包含的商品
                                Goods goodsTemp = goodsDAO.findById(orderGoodsTemp.getGoodsId());
                                // 查看此商品对顶级推荐人是否有特殊佣金
                                GoodsCommission specialCommission = goodsCommissionDAO.findByGoodsIdAndBuyerId(goodsTemp.getGoodsId(), topBuyerId);
                                // 查看此商品对此一级下线人员是否有特殊佣金
                                GoodsCommission firstLevelXiaXian_specialCommission = goodsCommissionDAO.findByGoodsIdAndBuyerId(goodsTemp.getGoodsId(), buyerId);
                                double firstLevelXiaXian_commission_number = firstLevelXiaXian_specialCommission == null ? (goodsTemp.getGoodsCommission() == null ? 0 : goodsTemp.getGoodsCommission()) : firstLevelXiaXian_specialCommission.getGoodsCommission();
                                if (specialCommission == null)
                                {
                                    if (goodsTemp.getGoodsCommission() != null)
                                    {
                                        day_commission = day_commission.add(new BigDecimal(goodsTemp.getGoodsCommission() - firstLevelXiaXian_commission_number).multiply(new BigDecimal(orderGoodsTemp.getGoodsNumber())));
                                    }

                                    // 存储佣金明细
                                    CommissionDetailRecord detailRecordFromDB = commissionDetailRecordDAO.findByBuyerIdAndOrderIdAndGoodsId(topBuyerId, oT.getOrderId(), goodsTemp.getGoodsId());
                                    if (detailRecordFromDB == null)
                                    {
                                        CommissionDetailRecord detailRecord = new CommissionDetailRecord();
                                        detailRecord.setRecordId(CM.getRandomTwentyFivePrimaryKeyId());
                                        detailRecord.setBuyerId(topBuyerId);
                                        detailRecord.setOrderId(oT.getOrderId());
                                        detailRecord.setGoodsId(goodsTemp.getGoodsId());
                                        detailRecord.setGoodsNumber(orderGoodsTemp.getGoodsNumber());
                                        detailRecord.setBuyerCommission(new BigDecimal(goodsTemp.getGoodsCommission() - firstLevelXiaXian_commission_number).multiply(new BigDecimal(orderGoodsTemp.getGoodsNumber())).doubleValue());
                                        detailRecord.setRecordTime(new Timestamp(day_beginTime.getTime()));
                                        commissionDetailRecordDAO.save(detailRecord);
                                    }
                                }
                                else
                                {
                                    day_commission = day_commission.add(new BigDecimal(specialCommission.getGoodsCommission() - firstLevelXiaXian_commission_number).multiply(new BigDecimal(orderGoodsTemp.getGoodsNumber())));

                                    // 存储佣金明细
                                    CommissionDetailRecord detailRecordFromDB = commissionDetailRecordDAO.findByBuyerIdAndOrderIdAndGoodsId(topBuyerId, oT.getOrderId(), goodsTemp.getGoodsId());
                                    if (detailRecordFromDB == null)
                                    {
                                        CommissionDetailRecord detailRecord = new CommissionDetailRecord();
                                        detailRecord.setRecordId(CM.getRandomTwentyFivePrimaryKeyId());
                                        detailRecord.setBuyerId(topBuyerId);
                                        detailRecord.setOrderId(oT.getOrderId());
                                        detailRecord.setGoodsId(goodsTemp.getGoodsId());
                                        detailRecord.setGoodsNumber(orderGoodsTemp.getGoodsNumber());
                                        detailRecord.setBuyerCommission(new BigDecimal(specialCommission.getGoodsCommission() - firstLevelXiaXian_commission_number).multiply(new BigDecimal(orderGoodsTemp.getGoodsNumber())).doubleValue());
                                        detailRecord.setRecordTime(new Timestamp(day_beginTime.getTime()));
                                        commissionDetailRecordDAO.save(detailRecord);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            currentMonthCommission = commissionDayRecordDAO.getTotalCommissionByBuyerIdAndBeginTimeAndEndTime(buyerId, month_beginTime, month_endTime);
            if (currentMonthCommission >= 0)
            {
                currentMonthCommission = day_commission.add(new BigDecimal(currentMonthCommission)).doubleValue();

                infoMap.put("totalBuyerNumber", totalBuyerNumber);
                infoMap.put("dayOrderNumber", dayOrderNumber);
                infoMap.put("dayGoodsNumber", dayGoodsNumber);
                infoMap.put("dayCommission", day_commission.doubleValue());
                infoMap.put("currentMonthCommission", currentMonthCommission);

                return infoMap;
            }
        }

        return null;
    }

    private Map<String, Object> getBuyerFirstLevelXiaXianPreCommissionInfo(String buyerId, String topBuyerId, Date day_beginTime, Date day_endTime, Date month_beginTime, Date month_endTime)
    {
        int onePageSize_2 = 2;
        int onePageSize_5 = 5;
        int onePageSize_10 = 10;

        Map<String, Object> infoMap = new HashMap<String, Object>();

        // 找到此人的所有一级下线买家
        int buyer_number_of_this_introducer = buyerDAO.getTotalCountByBuyerIntroducer(buyerId);
        if (buyer_number_of_this_introducer == 0)
        {
            infoMap.put("totalBuyerNumber", 0);
            infoMap.put("dayOrderNumber", 0);
            infoMap.put("dayGoodsNumber", 0);
            infoMap.put("dayCommission", 0.0);
            infoMap.put("currentMonthCommission", 0.0);

            return infoMap;
        }
        else if (buyer_number_of_this_introducer > 0)
        {
            int totalBuyerNumber = buyer_number_of_this_introducer;
            int dayOrderNumber = 0;
            int dayGoodsNumber = 0;
            BigDecimal day_commission = new BigDecimal(0);
            double currentMonthCommission = 0;

            int ttpTemp2 = buyer_number_of_this_introducer % onePageSize_5 == 0 ? buyer_number_of_this_introducer / onePageSize_5 : buyer_number_of_this_introducer / onePageSize_5 + 1;
            for (int j = 1; j <= ttpTemp2; j++)
            {
                List<Buyer> buyerListOfThisIntroducer = buyerDAO.getListByIndexAndPageSizeAndBuyerIntroducer(j, onePageSize_5, buyerId);
                for (Buyer bT : buyerListOfThisIntroducer)
                {
                    // 找到下线买家当日已付款的订单
                    int order_count = orderDAO.getTotalCountPayedOrderByBuyIdAndBeginTimeAndEndTime(bT.getBuyerId(), day_beginTime, day_endTime);

                    // 设置当日订单数量
                    dayOrderNumber += order_count;

                    int ttpTemp3 = order_count % onePageSize_10 == 0 ? order_count / onePageSize_10 : order_count / onePageSize_10 + 1;
                    for (int k = 1; k <= ttpTemp3; k++)
                    {
                        List<Order> orderList = orderDAO.getListPayedOrderByBuyerIdAndIndexAndPageSizeAndBeginTimeAndEndTime(bT.getBuyerId(), k, onePageSize_10, day_beginTime, day_endTime);
                        for (Order oT : orderList)
                        {
                            List<OrderGoods> orderGoodsList = orderGoodsDAO.findByOrderId(oT.getOrderId());
                            for (OrderGoods orderGoodsTemp : orderGoodsList)
                            {
                                // 设置当日商品数量
                                dayGoodsNumber += orderGoodsTemp.getGoodsNumber();

                                // 找到每个订单所包含的商品
                                Goods goodsTemp = goodsDAO.findById(orderGoodsTemp.getGoodsId());
                                // 查看此商品对顶级推荐人是否有特殊佣金
                                GoodsCommission specialCommission = goodsCommissionDAO.findByGoodsIdAndBuyerId(goodsTemp.getGoodsId(), topBuyerId);
                                // 查看此商品对此一级下线人员是否有特殊佣金
                                GoodsCommission firstLevelXiaXian_specialCommission = goodsCommissionDAO.findByGoodsIdAndBuyerId(goodsTemp.getGoodsId(), buyerId);
                                double firstLevelXiaXian_commission_number = firstLevelXiaXian_specialCommission == null ? (goodsTemp.getGoodsCommission() == null ? 0 : goodsTemp.getGoodsCommission()) : firstLevelXiaXian_specialCommission.getGoodsCommission();
                                if (specialCommission == null)
                                {
                                    if (goodsTemp.getGoodsCommission() != null)
                                    {
                                        day_commission = day_commission.add(new BigDecimal(goodsTemp.getGoodsCommission() - firstLevelXiaXian_commission_number).multiply(new BigDecimal(orderGoodsTemp.getGoodsNumber())));
                                    }
                                }
                                else
                                {
                                    day_commission = day_commission.add(new BigDecimal(specialCommission.getGoodsCommission() - firstLevelXiaXian_commission_number).multiply(new BigDecimal(orderGoodsTemp.getGoodsNumber())));

                                }
                            }
                        }
                    }
                }
            }
            currentMonthCommission = commissionDayRecordDAO.getTotalCommissionByBuyerIdAndBeginTimeAndEndTime(buyerId, month_beginTime, month_endTime);
            if (currentMonthCommission >= 0)
            {
                currentMonthCommission = day_commission.add(new BigDecimal(currentMonthCommission)).doubleValue();

                infoMap.put("totalBuyerNumber", totalBuyerNumber);
                infoMap.put("dayOrderNumber", dayOrderNumber);
                infoMap.put("dayGoodsNumber", dayGoodsNumber);
                infoMap.put("dayCommission", day_commission.doubleValue());
                infoMap.put("currentMonthCommission", currentMonthCommission);

                return infoMap;
            }
        }

        return null;
    }

    private Map<String, Object> getGoodsSalesSummaryInfo(String goods_type_id, String goods_type_name, Sheet summary_sheet, Row summary_row, int row_index, Cell cell, CellStyle style_content, CellStyle style_content_highlight, Date month_start_date, Date month_end_date)
    {
        Map<String, Object> infoMap = new HashMap<String, Object>();

        int this_type_total_number = 0;
        BigDecimal this_type_total_money = new BigDecimal(0);

        int the_whole_goods_countInDB = goodsDAO.getGoodsTotalCountByTid(goods_type_id);

        if (the_whole_goods_countInDB > 0)
        {
            int ttpTemp = the_whole_goods_countInDB % onePageSize_5 == 0 ? the_whole_goods_countInDB / onePageSize_5 : the_whole_goods_countInDB / onePageSize_5 + 1;
            for (int i = 1; i <= ttpTemp; i++)
            {
                List<Goods> goodsList = goodsDAO.getListByIndexAndPageSizeAnd_tid(i, onePageSize_5, goods_type_id);
                if (goodsList != null && goodsList.size() > 0)
                {
                    for (int j = 0; j < goodsList.size(); j++)
                    {
                        Goods temp_goods = goodsList.get(j);

                        summary_row = summary_sheet.createRow(row_index);
                        row_index++;

                        // 商品类型
                        cell = summary_row.createCell(0);
                        cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                        cell.setCellValue(goods_type_name);
                        cell.setCellStyle(style_content);
                        // 商品编号
                        cell = summary_row.createCell(1);
                        cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                        cell.setCellValue(temp_goods.getGoodsId());
                        cell.setCellStyle(style_content);
                        // 商品名称
                        cell = summary_row.createCell(2);
                        cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                        cell.setCellValue(temp_goods.getGoodsName());
                        cell.setCellStyle(style_content);

                        int month_sales_number = 0;
                        BigDecimal month_sales_money = new BigDecimal(0);

                        int the_whole_order_goods_countInDB = orderGoodsDAO.getTotalCountByGoodsId(temp_goods.getGoodsId());
                        if (the_whole_order_goods_countInDB <= 0)
                        {
                            // 月销售数量
                            cell = summary_row.createCell(3);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(String.valueOf(0));
                            cell.setCellStyle(style_content);
                            // 月销售额
                            cell = summary_row.createCell(4);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(String.valueOf(0));
                            cell.setCellStyle(style_content);
                        }
                        else
                        {
                            int ogttpTemp = the_whole_order_goods_countInDB % onePageSize_10 == 0 ? the_whole_order_goods_countInDB / onePageSize_10 : the_whole_order_goods_countInDB / onePageSize_10 + 1;
                            for (int m = 1; m <= ogttpTemp; m++)
                            {
                                List<OrderGoods> orderGoodsList = orderGoodsDAO.getListByGoodsIdAndIndexAndPageSize(temp_goods.getGoodsId(), m, onePageSize_10);
                                if (orderGoodsList != null && orderGoodsList.size() > 0)
                                {
                                    for (int n = 0; n < orderGoodsList.size(); n++)
                                    {
                                        OrderGoods temp_order_goods = orderGoodsList.get(n);
                                        Order temp_order = orderDAO.findById(temp_order_goods.getOrderId());
                                        GoodsHistory temp_goods_history = goodsHistoryDAO.findByGoodsIdAndGoodsUpdateTime(temp_order_goods.getGoodsId(), temp_order_goods.getGoodsUpdateTime());

                                        if (temp_order != null && temp_goods_history != null && temp_order.getOrderPayTime() != null && month_start_date.after(temp_order.getOrderPayTime()) == false && temp_order.getOrderPayTime().after(month_end_date) == false)
                                        {
                                            month_sales_number += temp_order_goods.getGoodsNumber();
                                            month_sales_money = month_sales_money.add(new BigDecimal(temp_goods_history.getGoodsPrice() * temp_order_goods.getGoodsNumber()));
                                        }
                                    }
                                }
                            }

                            // 月销售数量
                            cell = summary_row.createCell(3);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(String.valueOf(month_sales_number >= 0 ? month_sales_number : 0));
                            cell.setCellStyle(style_content);
                            // 月销售额
                            cell = summary_row.createCell(4);
                            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                            cell.setCellValue(String.valueOf(month_sales_money.doubleValue() > 0 ? month_sales_money.doubleValue() : "0"));
                            cell.setCellStyle(style_content);
                        }

                        this_type_total_number += month_sales_number >= 0 ? month_sales_number : 0;
                        this_type_total_money = this_type_total_money.add(month_sales_money);
                    }
                }
            }
        }
        if (the_whole_goods_countInDB > 0)
        {
            summary_row = summary_sheet.createRow(row_index);
            row_index++;

            // 此类型合计
            cell = summary_row.createCell(2);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue(goods_type_name + "合计");
            cell.setCellStyle(style_content);

            // 月销售数量
            cell = summary_row.createCell(3);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue(String.valueOf(this_type_total_number));
            cell.setCellStyle(style_content_highlight);
            // 月销售额
            cell = summary_row.createCell(4);
            cell.setCellType(XSSFCell.CELL_TYPE_STRING);
            cell.setCellValue(String.valueOf(this_type_total_money.doubleValue() > 0 ? this_type_total_money.doubleValue() : "0"));
            cell.setCellStyle(style_content_highlight);
        }

        infoMap.put("row_index", row_index);
        infoMap.put("this_type_total_number", this_type_total_number);
        infoMap.put("this_type_total_money", this_type_total_money);
        return infoMap;
    }

    private Map<String, Object> getCommissionSummaryInfo(Buyer buyer, String goods_type_id, String goods_type_name, Sheet summary_sheet, Row summary_row, int row_index, Cell cell, CellStyle style_content, CellStyle style_content_highlight, Date month_start_date, Date month_end_date)
    {
        Map<String, Object> infoMap = new HashMap<String, Object>();

        int this_type_total_number = 0;
        BigDecimal this_type_total_money = new BigDecimal(0);

        int the_whole_goods_countInDB = goodsDAO.getGoodsTotalCountByTid(goods_type_id);

        if (the_whole_goods_countInDB > 0)
        {
            int ttpTemp = the_whole_goods_countInDB % onePageSize_5 == 0 ? the_whole_goods_countInDB / onePageSize_5 : the_whole_goods_countInDB / onePageSize_5 + 1;
            for (int i = 1; i <= ttpTemp; i++)
            {
                List<Goods> goodsList = goodsDAO.getListByIndexAndPageSizeAnd_tid(i, onePageSize_5, goods_type_id);
                if (goodsList != null && goodsList.size() > 0)
                {
                    for (int j = 0; j < goodsList.size(); j++)
                    {
                        Goods temp_goods = goodsList.get(j);

                        summary_row = summary_sheet.createRow(row_index);
                        row_index++;

                        // 买家类型
                        cell = summary_row.createCell(0);
                        cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                        cell.setCellValue(buyer.getBuyerType());
                        cell.setCellStyle(style_content);
                        // 买家编号
                        cell = summary_row.createCell(1);
                        cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                        cell.setCellValue(buyer.getBuyerId());
                        cell.setCellStyle(style_content);
                        // 买家名称(微信昵称)
                        cell = summary_row.createCell(2);
                        cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                        cell.setCellValue(CM.validIsEmptyWithTrim(buyer.getBuyerNickname()) ? "" : buyer.getBuyerNickname());
                        cell.setCellStyle(style_content);
                        // 商品类型
                        cell = summary_row.createCell(3);
                        cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                        cell.setCellValue(goods_type_name);
                        cell.setCellStyle(style_content);
                        // 商品编号
                        cell = summary_row.createCell(4);
                        cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                        cell.setCellValue(temp_goods.getGoodsId());
                        cell.setCellStyle(style_content);
                        // 商品名称
                        cell = summary_row.createCell(5);
                        cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                        cell.setCellValue(temp_goods.getGoodsName());
                        cell.setCellStyle(style_content);

                        int month_sales_number = 0;
                        BigDecimal month_sales_money = new BigDecimal(0);

                        int salesNumberFromDB = commissionDetailRecordDAO.getTotalGoodsSalesNumberByBuyerIdAndGoodsIdAndBeginTimeAndEndTime(buyer.getBuyerId(), temp_goods.getGoodsId(), month_start_date, month_end_date);
                        month_sales_number = salesNumberFromDB <= 0 ? 0 : salesNumberFromDB;
                        double commissionSummaryFromDB = commissionDetailRecordDAO.getTotalCommissionByBuyerIdAndGoodsIdAndBeginTimeAndEndTime(buyer.getBuyerId(), temp_goods.getGoodsId(), month_start_date, month_end_date);
                        month_sales_money = commissionSummaryFromDB <= 0 ? new BigDecimal(0) : new BigDecimal(commissionSummaryFromDB);

                        // 下线月度销售数量
                        cell = summary_row.createCell(6);
                        cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                        cell.setCellValue(String.valueOf(month_sales_number >= 0 ? month_sales_number : 0));
                        cell.setCellStyle(style_content);
                        // 个人佣金汇总金额
                        cell = summary_row.createCell(7);
                        cell.setCellType(XSSFCell.CELL_TYPE_STRING);
                        cell.setCellValue(String.valueOf(month_sales_money.doubleValue() > 0 ? month_sales_money.doubleValue() : "0"));
                        cell.setCellStyle(style_content);

                        this_type_total_number += month_sales_number >= 0 ? month_sales_number : 0;
                        this_type_total_money = this_type_total_money.add(month_sales_money);
                    }
                }
            }
        }

        infoMap.put("row_index", row_index);
        infoMap.put("this_type_total_number", this_type_total_number);
        infoMap.put("this_type_total_money", this_type_total_money);
        return infoMap;
    }
}
